Define a command-line interface by just giving it a description in the specific format.
docopt
helps you to:
For more information see docopt.org
R package docopt
is an implementation of docopt in the R language.
See my presentation on the useR! 2014 for more details.
The latest version of docopt
can be installed using:
library(devtools) # make sure to have devtools 1.4!install_github("docopt/docopt.R")
It is tested against the tests defined for the reference implementation. It passes most tests. It currently fails tests that
my_prog.R -v -v
should return list(v=2)
The tests can be run using devtools test()
and can be found in "inst/tests"
docopt uses the description of the command-line interface to parse command line arguments.
'usage: my_prog.R [-a -r -m <msg>] options: -a Add -r Remote -m <msg> Message' -> doclibrary(docopt)# retrieve the command-line argumentsopts <- docopt(doc)# what are the options? Note that stripped versions of the parameters are added to the returned liststr(opts)
## List of 3
## $ -a: logi FALSE
## $ -r: logi FALSE
## $ -m: chr "<msg>"
## $ a: logi FALSE
## $ r: logi FALSE
## $ m: chr "<msg>"
# or set them manuallyopts <- docopt(doc, "-m Hello")str(opts)
## List of 3
## $ -a: logi FALSE
## $ -r: logi FALSE
## $ -m: chr "Hello"
## $ a: logi FALSE
## $ r: logi FALSE
## $ m: chr "Hello"
There is an issue with using -g
and -gui
with docopt.R
as reported on Stackoverflow. Rscript
filters on -g
and -gui
before docopt.R
can access them.
version 0.6.1
version 0.6
version 0.4.5
version 0.4.4
print
method for docopt (issue @12, thanks to @eddelbuettel)version 0.4.3.1
version 0.4
version 0.3
strip_names
to docopt (suggestion of @eddelbuettel)