[R] Arguments for Rcmd BATCH

Prof Brian Ripley ripley at stats.ox.ac.uk
Sun Jan 11 02:23:04 CET 2009


I suggested you use Rscript, please do.

R CMD BATCH is the Unix-alike notation.  Rcmd BATCH is the recommended 
way on Windows, but R CMD BATCH is also accepted.

There is nothing to reproduce here, so here is a simple example.

tystie% cat foo.R
args <- commandArgs(TRUE)
print(args)

tystie% Rscript foo.R parms=1:33
[1] "parms=1:33"

You can redirect the output as you wish.

On Sun, 11 Jan 2009, Andrew Hicks wrote:

> Dear Professor Ripley,
>
> Firstly, thank you very much for your advice. I was not aware my R was so
> old. Sorry I must have missed the instruction on reading the posting
> guidelines.
>
> I have updated it and it now runs again. This is a big step forward. However
> it is not running properly (or I am doing something wrong).
>
> There are still two problems may I ask for your help with please?
>
> 1. When I call the script it fails with the following message in the output
> file:
>
>> ##First read in the arguments listed at the command line
>> args <- commandArgs(TRUE)
> Error in commandArgs(TRUE) : unused argument(s) (TRUE)
> Execution halted
>
> 2. The diagnostic details (that should be going to test01b.ROUT are now
> going to strange places, overwriting the test01b.R file if I do not include
> the < and > redirectors.
>
> I am now using the following syntax, from the manual:
>
> Rcmd BATCH --no-save --no-restore --args parms=c(1,2,3) < test01b.R >
> test01b.ROUT

That's nothing like what is documented.

> Currently it is writing the output to "parms=c(1,2,3).ROUT"
>
> This is attached but says "fatal error cannot open file "--args"
>
> The file test01b.ROUT is created but empty.
>
> I get the same results if I start it with R CMD BATCH ...
>
> Is the a difference between R CMD... and Rcmd... please? The manual is not
> very clear on this.
>
> I am sorry to impose on you but guess I am still doing something wrong. I
> have looked through the documentation but cannot find much on this or many
> examples.
>
> Many thanks,
>
> Andrew Hicks
>
>
> -----Original Message-----
> From: Prof Brian Ripley [mailto:ripley at stats.ox.ac.uk]
> Sent: 10 January 2009 18:18
> To: Andrew Hicks
> Cc: r-help at r-project.org
> Subject: Re: [R] Arguments for Rcmd BATCH
>
> Your R is far too old, and in particular too old for the example you
> are trying.
>
> Please do you as asked in the posting guide to do before posting, and
> upgrade.  Then you will have Rscript, as described in the current 'An
> Introduction to R' manual for this purpose (with examples).
>
> On Sat, 10 Jan 2009, Andrew Hicks wrote:
>
>> Sorry to bother you and I hope this will be easy to solve.
>>
>>
>> I am trying to run R scripts in batch, called from another programme,
> under
>> Windows XP. I have R 2.4.1
>>
>>
>>
>> I need to be able to pass a list of numeric arguments to the script as
> well.
>>
>>
>>
>> The Rscript and its input data file are attached.
>>
>>
>>
>> I have been trying the syntax below but it doesn't work:
>>
>>
>>
>> Rcmd BATCH -no-save -no-restore -args parms=c(1,2,3) test01b.R
>>
>>
>>
>> (each of these BATCH options is preceded by 2 - characters, but my Outlook
>> is munging them together here)
>>
>>
>>
>> The script then accesses (or tries to) the variables as parms[1],
> parms[2],
>> etc.
>>
>>
>>
>> I get the respose "unable to open input file" at the command line and no
>> other diagnostic output.
>>
>>
>>
>> I got this syntax from p85 of the R-Intro doc and from the website
>> http://quantitative-ecology.blogspot.com/search/label/scripts. I could not
>> find any other illustrations or instructions of how to use args with
> BATCH.
>>
>>
>>
>> Without using any parameter args it otherwise runs fine.
>>
>>
>>
>> Please can you advise what am I doing wrong and how should this command be
>> structured? Do I also need to change the way the script is accessing the
>> arguments?
>>
>>
>>
>> Many thanks,
>>
>>
>>
>> Andrew Hicks
>>
>>
>
> -- 
> 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
>

-- 
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