Thursday, 17 February 2011

rrun - a bash R wrapper

rrun - A script to wrap around R, passing some variables.

First some motivation, what is the problem?

The default command line interface for R is a bit idiosyncratic, and there are no defaults:

~$ R
Fatal error: you must specify '--save', '--no-save' or '-vanilla'


someone went out of their way to deliberately make it behave that way! This is a language which is taking no prisoners.


~/r$ r --help
Usage: C:\Program Files\R\R-2.12.1\bin\r.exe [command args]

where 'command args' can be

  --arch n   for n=i386, x64, 32 or 64
  any other arguments listed by C:\Program Files\R\R-2.12.1\bin\r.exe --arch i386 --help

Its rude to point and stare!

~$ r --arch i386 --help
Usage: Rterm [options] [< infile] [> outfile] [EnvVars]

Start R, a system for statistical computation and graphics, with the
specified options

EnvVars: Environmental variables can be set by NAME=value strings

Options:
  -h, --help            Print usage message and exit
  --version             Print version info and exit
  --encoding=enc        Specify encoding to be used for stdin
  --encoding enc        ditto
  --save                Do save workspace at the end of the session
  --no-save             Don't save it
  --no-environ          Don't read the site and user environment files
  --no-site-file        Don't read the site-wide Rprofile
  --no-init-file        Don't read the .Rprofile or ~/.Rprofile files
  --restore             Do restore previously saved objects at startup
  --no-restore-data     Don't restore previously saved objects
  --no-restore-history  Don't restore the R history file
  --no-restore          Don't restore anything
  --vanilla             Combine --no-save, --no-restore, --no-site-file,
                          --no-init-file and --no-environ
  --min-vsize=N         Set vector heap min to N bytes; '4M' = 4 MegaB
  --max-vsize=N         Set vector heap max to N bytes;
  --min-nsize=N         Set min number of cons cells to N
  --max-nsize=N         Set max number of cons cells to N
  --max-mem-size=N      Set limit for memory to be used by R
  --max-ppsize=N        Set max size of protect stack to N
  -q, --quiet           Don't print startup message
  --silent              Same as --quiet
  --slave               Make R run as quietly as possible
  --verbose             Print more information about progress
  --internet2           Use Internet Explorer for proxies etc.
  --args                Skip the rest of the command line
  --ess                 Don't use getline for command-line editing
                          and assert interactive use
  -f file               Take input from 'file'
  --file=file           ditto
  -e expression         Use 'expression' as input

One or more -e options can be used, but not together with -f or --file

An argument ending in .RData (in any case) is taken as the path
to the workspace to be restored (and implies --restore)



Or: R CMD command args

where 'command' is one of:
  INSTALL  Install add-on packages
  REMOVE   Remove add-on packages
  SHLIB    Make a DLL for use with dynload
  BATCH    Run R in batch mode
  build    Build add-on packages
  check    Check add-on packages
  Rprof    Post process R profiling files
  Rdconv   Convert Rd format to various other formats
  Rdiff    difference R output files
  Rd2dvi   Convert Rd format to DVI
  Rd2pdf   Convert Rd format to PDF
  Rd2txt   Convert Rd format to pretty text
  Sd2Rd    Convert S documentation to Rd format
  Stangle  Extract S/R code from Sweave documentation
  Sweave   Process Sweave documentation
  config   Obtain configuration information about R
  open     Open a file via Windows file associations
  texify   Process a latex file

Use
  R CMD command --help
for usage information for each command.

I think we may need some help here.

A simple interface

rrun is intended to simplify the above, or at least be a handy place for my defaults and to enable me to pass parameters to R in addition to an input file of R commands.

sorry about the escaping

rrun s=\"nice\" f=1 s.R


Where s.R contains

print(s)
print(f)

The result:

~/r$ rrun s=\"nice\" f=1 ls.R
> # Temporary file generated by rrun
> # Date: Thu Feb 17 21:11:26 GMTST 2011
> # Command: rrun s="nice" f=1 ls.R
> #
> s="nice"
> f=1
> print(s)
[1] "nice"
> print(f)
[1] 1
> warnings()
NULL
>
~/r$

No comments:

Post a Comment