Re: [R] quick question : interpolating file name in pipe command

From: David Winsemius <dwinsemius_at_comcast.net>
Date: Thu, 05 May 2011 17:50:11 -0400

On May 5, 2011, at 5:15 PM, Abhishek Pratap wrote:

> Hi Guys
>
> I am trying to read a bunch of files in the loop but pipe function
> which I use to cut few columns is somehow unable to interpolate the
> file variable.
>
>
> eg:
>
>> file="check.txt"
>> data <- read.table(pipe("cut -f 2,3 file"), sep="\t",
>> col.names=c('pos','cov') )

I do not see where you allowed the substitution of the character vector file into the pipe argument.
Perhaps:

data <- read.table(pipe(paste("cut -f 2,3", file)), sep="\t", col.names=c('pos','cov') )

(Bad practice to name variables "file".)

I didn't use tabs but rather spaces:

check.txt was a single line file

ttt tt rr ttt

 > data <- read.table(pipe(paste("cut -f 2,3", file)), col.names=c('pos','cov') )
 > data
   pos cov
1 ttt tt
2 rr ttt

> cut: file: No such file or directory
>
> how can I pass variable file to pipe so that it can be interpolated.
>
> Thanks!
> -Abhi
>
> ______________________________________________
> R-help_at_r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

David Winsemius, MD
West Hartford, CT



R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Thu 05 May 2011 - 21:52:37 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 05 May 2011 - 22:00:05 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive