[R] Working with R batch

Prof Brian D Ripley ripley at stats.ox.ac.uk
Thu Apr 6 08:32:05 CEST 2000

On Thu, 6 Apr 2000, Shai Shen-Orr wrote:

> Hi all,
> I'm trying to invoke R from a perl program, using R BATCH.  My original
> R program wrote an output to a file and plotted a graph.  I'm having
> problems with the following three things:
> 1) To get the output file name form the perl program I wrote the
> following, in my R program:
>  commandArguments <- commandArgs();
> outputFile <- commandArguments[length(commandArguments)];
> This seems to not have worked.  Any ideas on why, or how else should I 
> be doing it ?

It gives the command arguments to _R_. BATCH is a script that redirects
input and output.  By definition a C program can't find out the name of the
files (if they are files) used for its stdin and stdout in a portable way.
In R BATCH input is coming from a pipe, anyway.

If you are invoking R from Perl then I don't think you should be using
R BATCH, but R directly (or even calling the binary).

Just make the output name part of the R script, or use Perl to redirect the
R text output to whatever you want to do with it, when the name will be

> 2) For some reason when I'm using R BATCH, my plot doesn't come up, I
> remember reading someplace that sometimes there might be problems with
> graphics & batch, but does anybody know how to get passed them ?

Um. And what device are you trying to use?  The default device is not a
screen device but postscript, and postscript plots do not `come up'.  You
should open the device you want explicitly: for non-interactive use of R
the default on Unix is to open a postscript device with file="Rplots.ps".
If you want a screen device use x11(), and ensure that you have some means
of looking at it before R terminates at the end of the input script.

> 3) How can I print a plot ?  Is it only through the postscript() command
> ?

If you want a hardcopy of the plot you can use any means you like, for
example to print an x11() device's window via your window manager, or use
dev2bitmap to grab the plot as a bitmap.  Basically for R _on Unix_ the
common format for printable plot files is PostScript, but there is also a
pictex device.  (A direct PDF device is at least a dream, and Windows has
other devices based on its GDI and producing bitmap formats such as PNG and
JPEG. No one has asked for a PCL (LaserJet) interface, which older programs
such as S-PLUS support.  People have talked about fig and similar formats

I suspect you will find a few files with the name Rplots.ps around.

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