Take a look at Rweb from Jeff Banfield (http://www.math.montana.edu/Rweb/) or Rcgi which is a CGI WWW interface to R by Mark J Ray. This information is also mention in the FAQ. "Chris Milkosky" <c.milkosky at xpedite. To: "r-mailing-list" <r-help at stat.math.ethz.ch> com> cc: Sent by: Subject: [R] non-interactive R usage... owner-r-help at stat.ma th.ethz.ch 10/05/2001 09:23 AM <Newbie alert> Hello all! </Newbie alert> =) Hi all, First of all, I'm new to R and I'm REALLY REALLY impressed by it. It's an asset to the open source community. I can't begin to say how glad I am to have stumbled across it in freshmeat.net... Kudos to the developers - you've done a great job. OK - my question may be answered by looking through documentation (I did RTFM), but I haven't noticed anything yet. I think I must just be missing something though. Does R give you the capability to run a script (read as non-interactive) that would perform a statistical task, and then send output to a file? For example: read a set of data from a file, generate a JPEG _file_ containing a plot of the data (with some specific stat calcs plotted of course), and then exit? I do capacity planning and would like to be able to have JPEG plots of real time statistical data appear on web pages, so I'm thinking that a CGI can be executed that starts R up, generates a plot, and writes it to a file. We currently use gnuplot, but with all of the statistical needs we have, it is turning out to be less flexible than we had hoped. Has this been done before? Could it be? If so, can we pass command line parameters to our R scripts somehow? Thanks, Chris -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. -.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._. _._._ -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
I just try the following on Linux (Mandrake7.1) and it works: file (tryplot.R: jpeg("tryplot.jpg") plot(rnorm(100)) dev.off()>From the shell prompt:R --no-save < tryplot.R > tryplot.Rout This generated the JPEG file, and dump the R session text to tryplot.Rout. If I understand correctly, jpeg() will *not* work with R BATCH, since it depends on x11(), and x11() isn't available when run under batch mode. Andy> -----Original Message----- > From: Chris Milkosky [mailto:c.milkosky at xpedite.com] > Sent: Friday, October 05, 2001 9:24 AM > To: r-mailing-list > Subject: [R] non-interactive R usage... > > > <Newbie alert> Hello all! </Newbie alert> =) > > Hi all, > > First of all, I'm new to R and I'm REALLY REALLY impressed by > it. It's an asset to the open source community. I can't begin to say > how glad I am to have stumbled across it in freshmeat.net... > Kudos to the developers - you've done a great job. > > OK - my question may be answered by looking through > documentation (I did RTFM), but I haven't noticed anything > yet. I think I must > just be missing something though. > > Does R give you the capability to run a script (read as > non-interactive) that would perform a statistical task, and > then send output > to a file? For example: read a set of data from a file, > generate a JPEG _file_ containing a plot of the data (with > some specific > stat calcs plotted of course), and then exit? > > I do capacity planning and would like to be able to have JPEG > plots of real time statistical data appear on web pages, so I'm > thinking that a CGI can be executed that starts R up, > generates a plot, and writes it to a file. We currently use > gnuplot, but with > all of the statistical needs we have, it is turning out to be > less flexible than we had hoped. > > Has this been done before? Could it be? If so, can we pass > command line parameters to our R scripts somehow? > > Thanks, > > Chris > > > -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. > -.-.-.-.-.-.-.-.- > 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 > _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._. > _._._._._._._._._ >-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
I run scripts in R like this: R --vanilla < script.R This is on Linux/Unix. Don't know about DOS/Windows. But I learned about it from looking at the R man page: man R. There is also a BATCH mode. I haven't tried that. See help(BATCH) Jon -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
There are a number of ways of using R non-interactively. The simplest method is just to put your R commands in a file, say 'myscript.R' and do (Under Unix/Linux:) R --no-save < myscript.R > myscript.out (Under MS-Windows) Rterm < myscript.R > myscript.out This will run R, feeding it the commands in 'myscript.R' and send the output to 'myscript.out'. Note that if you want graphics saved to a file that you should explicitly open (and then close!) the desired device. -Greg > -----Original Message----- > From: Chris Milkosky [mailto:c.milkosky at xpedite.com] > Sent: Friday, October 05, 2001 9:24 AM > To: r-mailing-list > Subject: [R] non-interactive R usage... > > > <Newbie alert> Hello all! </Newbie alert> =) > > Hi all, > > First of all, I'm new to R and I'm REALLY REALLY impressed > by it. It's an asset to the open source community. I > can't begin to say > how glad I am to have stumbled across it in > freshmeat.net... Kudos to the developers - you've done a great job. > > OK - my question may be answered by looking through > documentation (I did RTFM), but I haven't noticed anything > yet. I think I must > just be missing something though. > > Does R give you the capability to run a script (read as > non-interactive) that would perform a statistical task, and > then send output > to a file? For example: read a set of data from a file, > generate a JPEG _file_ containing a plot of the data (with > some specific > stat calcs plotted of course), and then exit? > > I do capacity planning and would like to be able to have > JPEG plots of real time statistical data appear on web pages, so I'm > thinking that a CGI can be executed that starts R up, > generates a plot, and writes it to a file. We currently > use gnuplot, but with > all of the statistical needs we have, it is turning out to > be less flexible than we had hoped. > > Has this been done before? Could it be? If so, can we > pass command line parameters to our R scripts somehow? > > Thanks, > > Chris > > > -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. > -.-.-.-.-.-.-.-.-.- > 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._. _._ LEGAL NOTICE Unless expressly stated otherwise, this message is confidential and may be privileged. It is intended for the addressee(s) only. Access to this E-mail by anyone else is unauthorized. If you are not an addressee, any disclosure or copying of the contents of this E-mail or any action taken (or not taken) in reliance on it is unauthorized and may be unlawful. If you are not an addressee, please inform the sender immediately. -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Chris Milkosky <c.milkosky at xpedite.com> wrote:> Does R give you the capability to run a script (read as non-interactive) that > would perform a statistical task, and then send output to a file? > ...can we pass command line parameters to our R scripts somehow?One way to pass arguments and flags is through a Perl wrapper. This also allows you to set up environment variables appropriately in a Unix cron job. Here's my template. I'm not sure about graphics, though. ###### Begin Code: ###### #!/usr/local/bin/perl -s (($arg1, $arg2) = @ARGV) || die "Must supply 2 arguments"; $f += 0; # -f flag, force numeric $ENV{"R_LIBS"} = "$ENV{SetThisAppropriately}/Rlib"; $| = 1; # Don't buffer Perl output $script = "/tmp/rwrap$$.R"; $outfile = "/tmp/rwrap$$.out"; open(SCRIPT, ">$script"); print SCRIPT <<EOF; arg1 <- "$arg1" arg2 <- "$arg2" fflag <- $f EOF print SCRIPT <<'EOF'; Z<-require(misc, q=T) # Quietly! # YOUR CODE HERE q() EOF close(SCRIPT); system("R --vanilla --slave < $script > $outfile"); $? && die "Aborted in R with errcode $?"; # Check for successful R completion unlink $script; # The script remains for debugging if failure ####### End Code ####### -- David Brahm (brahm at alum.mit.edu) -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._