[R] passing args from the command line

Uwe Ligges ligges at statistik.uni-dortmund.de
Tue Jan 1 17:02:04 CET 2008



Richard Müller wrote:
> Happy New Year to all!
> 
> I want to run a script from a directory on a central server on different 
> machines, linux and windows. To determine which machine is calling the script 
> I want to pass an argument with the call (e.g. for choosing the display 
> device, for writing path names etc.)
> I tried the following:
> R CMD BATCH --args gui=4 /home/script.R script.out (linux)
> resp. Rcmd BATCH --args gui=1 Z:/script.R script.out (windows)

Note the help page
R CMD BATCH --help

You probably want

   R CMD BATCH "--args gui=1" Z:/script.R script.out
or
   R --no-save --args gui=1 < Z:/script.R > script.out


Uwe Ligges



> The script started with
> args(commandArgs(TRUE)) # thanks to James Forester for his R-concerning blog
> 
> script.out says: Error in commandArgs(TRUE): unused argument(s) (linux)
> windows says: input file --args cannot be opened
> 
> Something must be going wrong (but different things on Win and Linux) (but 
> what?)
> Richard
>




More information about the R-help mailing list