The option parser is generated based on the docstring above that is passed to docopt function.
docopt parses the usage pattern ("Usage: ...") and option descriptions
(lines starting with dash "-") and ensures that the program invocation matches the
usage pattern; it parses options, arguments and commands based on that.
The basic idea is that a good help message has all necessary information in it to make a parser.
To execute your command-line application you need to provide path to command-line executable file
(i.e. naval_fate.R in our case) and provide relevant command-line arguments/options/commands.
docopt function returns a list of command-line parameters and their
corresponding values that can be accessed via $ within your command-line
application.
In case if provided command-line parameters are inconsistent with the
"Usage: ..." pattern the error message will be printed along with
usage pattern examples.
docopt
docopthelps you to:R package
docoptis an implementation of docopt in the R programming language. See my presentation on the useR! 2014 for more details.For more information see docopt.org
To try docopt in your browser visit try.docopt.org
Installation
The easiest way to get
docoptis to install from CRAN:Development version
The latest version of
docoptcan be installed from GitHub using devtools:Testing
It is tested against the tests defined for the reference implementation. It passes most tests. It currently fails tests that
my_prog.R -v -vshould returnlist(v=2)The tests can be run using
devtools::test()and can be found in “tests” directory.Usage
docoptuses the description of the command-line interface (i.e. help message docstring) to parse command-line arguments.The option parser is generated based on the docstring above that is passed to
docoptfunction.docoptparses the usage pattern ("Usage: ...") and option descriptions (lines starting with dash"-") and ensures that the program invocation matches the usage pattern; it parses options, arguments and commands based on that. The basic idea is that a good help message has all necessary information in it to make a parser.To execute your command-line application you need to provide path to command-line executable file (i.e.
naval_fate.Rin our case) and provide relevant command-linearguments/options/commands.For example
docoptfunction returns a list of command-line parameters and their corresponding values that can be accessed via$within your command-line application."Usage: ..."pattern the error message will be printed along with usage pattern examples.