[R] Renaming Rplots.ps from BATCH scripts.

Stephen Eglen S.J.Eglen at damtp.cam.ac.uk
Wed May 17 13:15:51 CEST 2006

I often use R CMD BATCH to run my files (e.g. script.R), and get the
output recorded in script.Rout -- this is great.  On my setup (R.2.3.0
on linux), if any plots are created, they get stored in Rplots.ps.
This can get confusing if I have several batch scripts in one

I've written a simple shell script to rename Rplots.ps to
e.g. script.Rout.ps so that later I can easily identify which script
created the original postscript file.  Just thought I'd share it in
case others were interested, or had comments.

## Run R in BATCH mode.

## Usage:
## rb infile

## First (and only argument) is the R script to run in batch.

## Check that the input file exists.
if [ -r ${in} ]
    ## I do not like .RData to be saved
    R CMD BATCH --no-save ${in}
    echo "File ${in} does not exist."
    exit -1

## if Rplots.ps is readable, rename it to X.Rout.ps
if [ -r Rplots.ps ]
    outps=`basename ${in} .R`.Rout.ps
    mv Rplots.ps ${outps}    

More information about the R-help mailing list