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!! Yiping -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
>From: yiping.fan at syngenta.com >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!! > >YipingI haven't tried this from within Perl, however, you can use R from a Unix command line like this: R --vanilla < my.R To see what the --vanilla switch does that your commands do not do, see the man page for R. (I'm not sure which parts are the important ones, but this works.) To get the output from R, I write to a file from R itself, using write() or whatever. I'm sure there are other ways, but it seems you have no objection to using files. See pay.R at the end of http://finzi.psych.upenn.edu/~baron/ for an unnecessarily complex example, in which R is used to write checks! (You can also use it to wash the dishes :) ) I used to do this sort of thing with Perl, but, really, R is just a better language, even for text processing, IMHO. Jon Baron -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Sorry, I think I misread this. I'll try to read more carefully in the future. Jon Baron -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._