commandArgs()
At present there is no official way to add arguments to R: commandArgs()
is intended to let you retrieve the standard arguments.
This has been discussed for a long time, but there are problems with doing
it consistently across platforms: for example Windows allows an extra
argument, the name of a .RData file, to allow file-association to work.
What you can do reliably across platforms is to pass information in
environment variables. Something like
NRUNS=1000 R --vanilla < test.R > test.Rout (Unix, sh)
Rterm NRUNS=100 --vanilla < test.R > test.Rout (Windows)
and have
nruns <- as.numeric(Sys.getenv("NRUNS"))
in the script test.R
On Mon, 5 May 2003, R A F wrote:
Apologies for asking about this, but I don't quite understand how this works after looking through the FAQ and the Help archives. Let's say I want to pass "1000" as an argument to R. I did the following:
R CMD BATCH --1000 infile outfile
When I do print( commandArgs() ), I see [1] ".../R.bin" "--restore" [3] "--save" "--no-readline" [5] "gui=none" "--1000" So commandArgs()[6] is the argument I want. Does one then go on and remove the "--" manually and cast this as numeric? If so, what's the usual way to do this? Or am I not understanding this mechanism properly?
There is no such mechanism at present.
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