Is there any convenient way to automatically parse command line arguments passed to R scripts?
Something like perl's Getopt::Long
?
Is there any convenient way to automatically parse command line arguments passed to R scripts?
Something like perl's Getopt::Long
?
Just to complement the Rscript answer:
We just use
argv
in littler. I had good luck with getopt, the older of the two available parsing packages.The simplest way is to use commandArgs(). Example - save the code below as "options.R":
Run using "Rscript options.R x y z". Result:
i.e. a list of 3 elements, one per argument.
There are three packages on CRAN:
argparse
andjson
(orsimplejson
) modules.Update:
May I introduce
ArgumentParser
in Xmisc package? It is a command line parser inspired by Python'sargparse
but it is Python-free.http://cran.r-project.org/web/packages/Xmisc/vignettes/Xmisc-ArgumentParser.pdf