Hello, I have written perl programs that extract data from a text file, process them, and create other text files, which I'd like to apply some statistics too (for example with R). I'd like to do it all in once , with a single script. I'm not familiar with R, I'd like to know if this task could be accomplished by creating a linux shells that launches the perl scripts and then "R functions" that maybe pass back some results to the system like in this schema: S ---> Perl H <----- E ---> R functions L <----- L Is it possible ? Where can I get information to do that? (to call R from a shell, in background) Are other better way to do that? Thank you very much! Enrico.
> -----Original Message----- > From: Enrico Curiotto [mailto:e_curiotto at yahoo.com] > Hello, > > I have written perl programs that extract data from a > text file, process them, and create other text files, > which I'd like to apply some statistics too (for > example with R). > > I'd like to do it all in once , with a single script. > I'm not familiar with R, I'd like to know if this task > could be accomplished by creating a linux shells that > launches the perl scripts and then "R functions" that > maybe pass back some results to the system like in > this schema: > > S ---> Perl > H <----- > E ---> R functions > L <----- > L >You can run R scripts in batch mode and direct output to file. That would be by far the simplest. Or, you could explore RSOAP to run R as a web service which allows creation of R sessions which persist (i.e. the binary data objects stay around) between requests from another application (which could include a Perl script using Perl's soap libraries). A third option is the Rserve system which allows connection to R sessions using TCP/IP from other software applications. See the R helpfile on the BATCH command (?BATCH) and/or http:ess.r-project.org/Zope/projects/RSOAP/ and/or http://stats.math.uni-augsburg.de/Rserve/ HTH, -Eric> Is it possible ? > Where can I get information to do that? (to call R > from a shell, in background) > > Are other better way to do that? > > Thank you very much! > > Enrico. > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html >This email message, including any attachments, is for the so...{{dropped}}
On Thu, 15 Jan 2004, Enrico Curiotto wrote:> Hello, > > I have written perl programs that extract data from a > text file, process them, and create other text files, > which I'd like to apply some statistics too (for > example with R). > > I'd like to do it all in once , with a single script. > I'm not familiar with R, I'd like to know if this task > could be accomplished by creating a linux shells that > launches the perl scripts and then "R functions" that > maybe pass back some results to the system like in > this schema: >You could call R in BATCH mode from the perl script using one of the system interface operators, e.g., "system", or use the 'Shell' module. I have also bumped (but didn't try yet) into R-Perl interface called RSPerl which might be much more than you what you need. I think it is under the "Omega" link in the R website. If not google for RSPerl. 'R --help' will give you pointers to running R in BATCH mode. Itay -------------------------------------------------------------- itayf at fhcrc.org Fred Hutchinson Cancer Research Center
Hi Enrico, As seen by other posts, there are many ways to accomplish this sort of thing. For simple tasks I've often found it easiest to call R from my script (in my case Python). I've not used BATCH mode and instead call R like this: R --slave --no-save < script.R A common setup for me is to have a functions.R file with routines I want to use and then to generate a small R script from within Python that sources functions.R and calls the functions with the proper variables as determined by the script. HTH, + seth
Ciao Enrico, I think you can skip to use a shell as you described. There are some ways to include R script in a perl script. I included below two examples I wrote for better understand. ###### prova1.pl ####### #!/usr/local/bin/perl open (FILE, ">test.txt"); print FILE "a,b,c,d,e\n1,2,3,4,5"; close FILE; ####### Start R code #### open (R_FH, "|/usr/local/bin/R --no-save --slave") or die "$!"; print R_FH qq{ data<-read.csv("test.txt") datamean<-mean(as.numeric(as.character(data[1,])), na.rm=TRUE) write(datamean, file="out.txt") quit(save='no',status=0) }; close R_FH; ##### end R #### open(FILE, "<out.txt"); while (<FILE>){ $mean= $_; } close FILE; print "Mean= ".$mean; or ######## prova2.pl ###### #!/usr/local/bin/perl open (FILE, ">test.txt"); print FILE "a,b,c,d,e\n1,2,3,4,5"; close FILE; ####### Start R code #### system("/usr/local/bin/R -q --vanilla < rscript.r > debug.out"); ##### end R #### open(FILE, "<out.txt"); while (<FILE>){ $mean= $_; } close FILE; print "Mean= ".$mean; ... in this way you can call the perl script only. Regards, Vittorio -----Original Message----- From: r-help-bounces at stat.math.ethz.ch [mailto:r-help-bounces at stat.math.ethz.ch]On Behalf Of Enrico Curiotto Sent: Friday, January 16, 2004 12:02 AM To: r-help at stat.math.ethz.ch Subject: [R] invoking R scripts from a linux shell ? Hello, I have written perl programs that extract data from a text file, process them, and create other text files, which I'd like to apply some statistics too (for example with R). I'd like to do it all in once , with a single script. I'm not familiar with R, I'd like to know if this task could be accomplished by creating a linux shells that launches the perl scripts and then "R functions" that maybe pass back some results to the system like in this schema: S ---> Perl H <----- E ---> R functions L <----- L Is it possible ? Where can I get information to do that? (to call R from a shell, in background) Are other better way to do that? Thank you very much! Enrico. ______________________________________________ R-help at stat.math.ethz.ch mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html