[R] read input from STDIN

Prof Brian Ripley ripley at stats.ox.ac.uk
Fri Dec 28 09:25:49 CET 2001

On Thu, 27 Dec 2001 yiping.fan at syngenta.com wrote:

> Hello,
>    I have a perl program which produces the input. Instead of print it to a
> file then let R read the file,
> I want to let R to read the input directly from the perl output,
> I am using  a PERL IPC::open2 module for this,
> local (*Read,*Writer);
> $pid = open2(\*Read, \*Writer, "R --no-save --slave< my.R")
> #input to R
> for(){
>   print Writer data;
> }
> close Writer;
> #R output
> @result = <Read>;
> How can "my.R"  read the stdin and figure out the relationship in the data?
> I tried realLines(), does not work.  Thank you very much for your help!!

It can't. You redirected the stdin of R to be the file my.R, and in any
Unix-alike OS that leaves the previous stdin unused.

You would do better to use the connections functions in R to read from a
fifo, and write your perl output to that fifo.

Next time please tell us your OS, R version and what exactly you did and
how it does not work.

Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch

More information about the R-help mailing list