[R] commandArgs usage and --args invokation

Prof Brian Ripley ripley at stats.ox.ac.uk
Sun Apr 1 09:18:22 CEST 2007


On Sat, 31 Mar 2007, ivo welch wrote:

> Dear R experts:
>
> I am a bit stymied by how the argument picking-off works in R batch file 
> usage.

You seem to mean 'R CMD BATCH' usage (there are other ways to run R in 
batch), and also I will assume you are talking only about a Unix-alike 
(these things are somewhat different on Windows).  Please do follow the R 
posting guide and provide basic information (and read the help).

In R 2.5.0 you probably want to use 'Rscript' instead for this sort of 
batch usage.

> $ cat commandArgs.R
> cat(" Command Line Arguments were ", commandArgs(), "\n");

We don't want the trailing ';': this is R not C.

> $ /usr/bin/R CMD BATCH commandArgs.R --args 1 2 3
>
> $ /usr/bin/R --args 1 CMD BATCH commandArgs.R
> ... I am now getting into interactive mode ?!  I guess it really is 
> skipping the rest of the command line

Yes, that is what --args is documented to do, skip the rest of the command 
line.  Try R --help

> $ /usr/bin/R CMD BATCH commandArgs.R --args 1
>
> $ ls -lt | head
> total 1628148
> -rw-rw-r-- 1 ivo ivo       827 Mar 31 21:47 --args
> ...

Please DO read the help here:

gannet% R CMD BATCH --help
Usage: R CMD BATCH [options] infile [outfile]

so you have 'options' in the wrong place, and --args is matching 
'outfile'.  As is says that only arguments starting with '-' are 
considered to be options, you cannot use '1' here as an option.  What you 
can do is

R CMD BATCH '--args 1' commandArgs.R

Once again, this is doing what it is documented to do.


> Could someone please let me know?
>
> [also, are there multi-core versions of R?  my guess is no, but since
> I have a second processor lying around, I am trying to get it into the
> fray.]
>
> A working example would be appreciated.

R is not multithreaded, but you can make use of multithreaded BLASes: see 
the R-admin installation manual.

-- 
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 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595



More information about the R-help mailing list