shntnu
2/24/2017 - 3:17 PM

Notes on using docopt

Notes on using docopt

Usage

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' -> doc

# load the docopt library
library(docopt)
# retrieve the command-line arguments
opts <- docopt(doc)
# what are the options? Note that stripped versions of the parameters are added to the returned list
str(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 manually
opts <- 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"