[R] commandArgs: feature request

Vadim Ogranovich vograno at arbitrade.com
Tue Jun 25 02:36:58 CEST 2002


Dear R-core Team,

As Thomas Lumley pointed out in one of his e-mails one can use commandArgs()
to get a copy of the command line arguments supplied when R session was
invoked and then use grep to extract parameters of interest.
His solution works very well if the custom options are passed by names, e.g.
--my-option=value, but what if one wants to pass parameters by their
positions. Then it's not easy to tell standard options from user-supplied
ones.
One possible solution would be to augment the return value of commandArgs()
with BOOL vector attribute that says whether it is a standard (reserved) R
option or not. Here is a usage example that I have in mind:

R BATCH --no-save 2001-01-01 3001-01-01 Foo/*.in batch.R

batch.R:

myArgs <- commandArgs()
myArgs <- myArgs[!attr(myArgs, "is.standard")]

start <- myArgs[1]
end <- myArgs[2]
files <- myArgs[-seq(2)]

# code
...

I am sure there are other (better) solutions, but having anything like this
would make it easier to integrate R  with shell scripts that invoke R as a
sub-task.

Thanks, Vadim
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list