Alberto Gobbi
2003-Feb-21 17:17 UTC
[R] Problem Writeing a pipe using R (stdin is consumed)
Hi everybody, I a, trying to use R as a pipe like this: cat inputData | R --silent RCommandFile >outputData The RCommandFile would contain something like readLines(stdin()). I have tryed various things and none did work cleanly. One possible solution is to use the pipe() function inside R and to pass in the "cat inputData" however this is not very convenient since I would like to use variable commands to generate the inputData which are much more complex than just "cat inputData" they might consist themselves of multiple pipes. The problem is that R uses the stdin for itself to read commands and I could not find any solution. Thanks a lot, Alberto
Huntsinger, Reid
2003-Feb-21 18:59 UTC
[R] Problem Writeing a pipe using R (stdin is consumed)
Perhaps a named pipe (aka fifo) would solve your problem? You could write to it from an arbitrary process and read from it from your R program. Reid Huntsinger -----Original Message----- From: Alberto Gobbi [mailto:agobbi at anadyspharma.com] Sent: Friday, February 21, 2003 11:16 AM To: r-help at stat.math.ethz.ch Subject: [R] Problem Writeing a pipe using R (stdin is consumed) Hi everybody, I a, trying to use R as a pipe like this: cat inputData | R --silent RCommandFile >outputData The RCommandFile would contain something like readLines(stdin()). I have tryed various things and none did work cleanly. One possible solution is to use the pipe() function inside R and to pass in the "cat inputData" however this is not very convenient since I would like to use variable commands to generate the inputData which are much more complex than just "cat inputData" they might consist themselves of multiple pipes. The problem is that R uses the stdin for itself to read commands and I could not find any solution. Thanks a lot, Alberto ______________________________________________ R-help at stat.math.ethz.ch mailing list http://www.stat.math.ethz.ch/mailman/listinfo/r-help ------------------------------------------------------------------------------
Alberto Gobbi
2003-Feb-21 20:53 UTC
[R] Problem Writeing a pipe using R (stdin is consumed)
Thanks for the answer!
However what I would like to ba able to do is something like:
perl -e 'print "1 2\n\2 2\n";' | R --silent commandFile
and commandFile would contain something like:
t<-read.table(file("t"), sep=" ")
print(t*2)
This would need read.table to get the original stdin() and the commands to be
read from a file.
The idea with the named pipe does not work either for the same reasons.
Thanks again,
Alberto
-----Original Message-----
From: M.Kondrin [mailto:mkondrin at hppi.troitsk.ru]
Sent: Friday, February 21, 2003 21:43 PM
To: R-Help
Subject: Re: [R] Problem Writeing a pipe using R (stdin is consumed)
M.Kondrin wrote:> May be R -slave ... will help?
> man R
> ...
> -q, --quiet
> Don't print startup message
>
> --silent
> Same as --quiet
>
> --slave
> Make R run as quietly as possible
>
> ...
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> http://www.stat.math.ethz.ch/mailman/listinfo/r-help
>
$ echo "h<-1; print(h)" | R --slave
[1] 1
$
______________________________________________
R-help at stat.math.ethz.ch mailing list
http://www.stat.math.ethz.ch/mailman/listinfo/r-help
But may be you will like to feed through pipe both data and commands? It will require to do some formatting of input but I think it will not be hard to do in perl. I mean something like that: echo "source(\"RCommands.R\");t<-matrix(c(1,2,3,4,5,6),ncol=2);print(process(t))" | R --slave You only need to substitute your data inside c() with all separators replaced with commas and specify number of columns in your data as ncol=... Good luck...
Alberto Gobbi
2003-Feb-22 23:24 UTC
[R] Problem Writeing a pipe using R (stdin is consumed)
Actually I must correct myself, the named pipe will work (thanks Reid!).
Also the suggestion to mix R commands and data should work, but I think I prefer
the named pipe. The datafile will be huge in my case like GB, so that is the
reason I do not want to use temporary files.
Thanks to everybody!
Alberto
-----Original Message-----
From: Alberto Gobbi
Sent: Friday, February 21, 2003 11:52 AM
To: R-Help
Subject: RE: [R] Problem Writeing a pipe using R (stdin is consumed)
Thanks for the answer!
However what I would like to ba able to do is something like:
perl -e 'print "1 2\n\2 2\n";' | R --silent commandFile
and commandFile would contain something like:
t<-read.table(file("t"), sep=" ")
print(t*2)
This would need read.table to get the original stdin() and the commands to be
read from a file.
The idea with the named pipe does not work either for the same reasons.
Thanks again,
Alberto
-----Original Message-----
From: M.Kondrin [mailto:mkondrin at hppi.troitsk.ru]
Sent: Friday, February 21, 2003 21:43 PM
To: R-Help
Subject: Re: [R] Problem Writeing a pipe using R (stdin is consumed)
M.Kondrin wrote:> May be R -slave ... will help?
> man R
> ...
> -q, --quiet
> Don't print startup message
>
> --silent
> Same as --quiet
>
> --slave
> Make R run as quietly as possible
>
> ...
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> http://www.stat.math.ethz.ch/mailman/listinfo/r-help
>
$ echo "h<-1; print(h)" | R --slave
[1] 1
$
______________________________________________
R-help at stat.math.ethz.ch mailing list
http://www.stat.math.ethz.ch/mailman/listinfo/r-help
______________________________________________
R-help at stat.math.ethz.ch mailing list
http://www.stat.math.ethz.ch/mailman/listinfo/r-help
Huntsinger, Reid
2003-Feb-24 16:26 UTC
[R] Problem Writeing a pipe using R (stdin is consumed)
The named pipe idea works for me:
basically,
$ mknod to_R p
$ echo "test this out" > to_R &
$ R CMD BATCH rtest.R out
where rtest.R is
con <- fifo("to_R", open="r")
print(readlines(con))
Reid Huntsinger
-----Original Message-----
From: Alberto Gobbi [mailto:agobbi at anadyspharma.com]
Sent: Friday, February 21, 2003 2:52 PM
To: R-Help
Subject: RE: [R] Problem Writeing a pipe using R (stdin is consumed)
Thanks for the answer!
However what I would like to ba able to do is something like:
perl -e 'print "1 2\n\2 2\n";' | R --silent commandFile
and commandFile would contain something like:
t<-read.table(file("t"), sep=" ")
print(t*2)
This would need read.table to get the original stdin() and the commands to
be read from a file.
The idea with the named pipe does not work either for the same reasons.
Thanks again,
Alberto
-----Original Message-----
From: M.Kondrin [mailto:mkondrin at hppi.troitsk.ru]
Sent: Friday, February 21, 2003 21:43 PM
To: R-Help
Subject: Re: [R] Problem Writeing a pipe using R (stdin is consumed)
M.Kondrin wrote:> May be R -slave ... will help?
> man R
> ...
> -q, --quiet
> Don't print startup message
>
> --silent
> Same as --quiet
>
> --slave
> Make R run as quietly as possible
>
> ...
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> http://www.stat.math.ethz.ch/mailman/listinfo/r-help
>
$ echo "h<-1; print(h)" | R --slave
[1] 1
$
______________________________________________
R-help at stat.math.ethz.ch mailing list
http://www.stat.math.ethz.ch/mailman/listinfo/r-help
______________________________________________
R-help at stat.math.ethz.ch mailing list
http://www.stat.math.ethz.ch/mailman/listinfo/r-help
------------------------------------------------------------------------------