Check out the getopt package.
On Fri, Apr 17, 2009 at 11:39 AM, Juergen Rose <rose at rz.uni-potsdam.de>
wrote:> Hi,
> I would like to call a R script sometimes with:
> ?R --slave --vanilla --args Debug=1 N=25 < test.R
> and sometimes with
> ?R --slave --vanilla Debug=1 < test.R
> or similar.
>
> Inside the R script I get the arguments with:
>
> args=(commandArgs(TRUE))
> if(length(args)==0){
> ?print("=== ? ?No arguments supplied. =============")
> }else{
> ?for(i in 1:length(args)){
> ? ?eval(parse(text=args[[i]]))
> ?}
> }
>
> But I don't know, how can I test inside the script if the parameter N
> was passed to script or not. I am looking for something like
> is.defined(N), but I could not find it until now.
>
> Any hint?
>
> Juergen
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>