Gabor Grothendieck | 1 May 2009 04:28
Picon

Re: Evaluating content of command line arguments

Check out the getopt package.

On Thu, Apr 30, 2009 at 10:10 PM, JiHO <jo.lists <at> gmail.com> wrote:
> 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?
(Continue reading)

JiHO | 1 May 2009 22:47
Picon

Re: Evaluating content of command line arguments

On 2009-April-30  , at 22:28 , Gabor Grothendieck wrote:

> Check out the getopt package.

Thanks! That's what I need.

JiHO
---
http://jo.irisson.free.fr/


Gmane