in reply to Re^3: Passing parameters to R script
in thread Passing parameters to R script

Here is simple function to parse unix way of parsing argument from R.

# # # EXAMPLE: # R --test=mydata.csv #> getopt('test') #[1] "mydata.csv" # getting numeric argument # R --N=123 #> getopt('N',numeric=T) #[1] 123 # getopt <- function(argname, numeric = F) { args <- commandArgs() argexp = sprintf('^--%s=',argname) idx <- regexpr(argexp, args); ret <- NA if ( any(idx > 0) ) { # found matching argument found <- args[idx > 0] value <- strsplit(found,"=") ret <- unlist(value)[2] } if ( numeric ) ret <- as.numeric(ret) ret }

cheers, c.okugami