[R] Using pipe for input data
Hayashi Soichi - shayas
Soichi.Hayashi at acxiom.com
Fri Aug 6 00:19:37 CEST 2004
Hi.
I have asked this question before and Aaron J. Mackey and Tony Plate gave me
some great insight but I still can't figure out how to do what I am trying
to accomplish. So let me ask again...
What I am trying to do is to make R read data from pipe (stdin).
Say I have following files on my directory
my.dat
apple 1
orange 2
grape 3
my.R
d <- read.table( stdin(), header=F, dec='.',
col.names=c("name","type"), na.strings=c("xxxx"))
summary(d)
and When I run this command
cat my.dat | R CMD BATCH --vanilla --slave my.R
I am expecting to see the summery report for the datasource my.dat
But here is what I actually see in my.Rout
> d <- read.table( stdin(), header=F, dec='.',
col.names=c("name","type"), na.strings=c("xxxx"))
0: summary(d)
1: proc.time()
2: Error in scan(file = file, what = what, sep = sep, quote = quote,
dec = dec, :
line 1 did not have 2 elements
Execution halted
If I execute the content of the my.R on regular R command line, I can
actually "type in" all datasource and creates the correct summery report. So
I don't know why I can make R to read the input from the piped datasource...
Has anybody done something like this?
Thanks,
Soichi Hayashi
**********************************************************************
The information contained in this communication is\ confiden...{{dropped}}
More information about the R-help
mailing list