Re: [R] commandArgs usage and --args invokation

From: Prof Brian Ripley <>
Date: Sun 01 Apr 2007 - 07:18:22 GMT

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,        
Professor of Applied Statistics,
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

______________________________________________ mailing list
PLEASE do read the posting guide
and provide commented, minimal, self-contained, reproducible code.
Received on Sun Apr 01 17:21:40 2007

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Sun 01 Apr 2007 - 08:30:35 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.