[R] Evaluating content of command line arguments
JiHO
jo.lists at gmail.com
Fri May 1 04:10:31 CEST 2009
Hello everyone,
I am writing an R script which will be provided with command line
arguments by a shell script. I read them with commandArgs() but I have
an issue to make that fool proof.
For example, with test.R containing:
args=commandArgs(trailingOnly=TRUE)
args
I get:
$ Rscript test_commandLineArgs.R 3 4 5
[1] "3" "4" "5"
Now, to make the input more flexible and robust, I want to pass
*named* arguments, so that the R script does not depend on the order
of arguments passed and can check which are present/absent etc. I.e.
$ Rscript test_commandLineArgs.R foo=3 bar=4 5
[1] "foo=3" "bar=4"
But I am stuck on how to actually execute the code within those
strings so as to get two variables foo and bar equal to 3 and 4
respectively. I looked at eval, deparse, substitute and all that but
did not find anything. Is that possible?
Otherwise I will resort to parsing the arguments with strsplit but I
would much prefer and more elegant solution.
Thank you very much in advance. Sincerely,
JiHO
---
http://jo.irisson.free.fr/
More information about the R-help
mailing list