Command-Line Interface Specification Language

Define a command-line interface by just giving it a description in the specific format.

version downloads Build Status

docopt helps you to:

  • define an interface for your command-line app, and
  • automatically generate a parser for it.

For more information see

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!

It is tested against the tests defined for the reference implementation. It passes most tests. It currently fails tests that

  • count arguments: 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>]
 -a        Add
 -r        Remote
 -m <msg>  Message' -> doc
# 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
## 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")
## 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

  • changed methods dependency to import (issue #35, thanks to @eddelbuettel). Should have be done earlier, but did work with R version <= 3.3

version 0.6

  • removed stringr dependency

version 0.4.5

  • Fixed single argument which embed a space (issue #11, thanks to @malcook)

version 0.4.4

  • Fixed arguments which embed a space (issue #11, thanks to @jennybc)
  • Added print method for docopt (issue @12, thanks to @eddelbuettel)


  • Fixed stringr dependency thanks to (@eddelbuettel)

version 0.4

  • Fixed repeating options (issue #8, thanks to @cboettig)
  • Fixed parsing after double -- (thanks to @ljos)
  • Fixed printing multiple usage statements (issue #7, thanks to @rgrannell1)

version 0.3

  • Breaking change! By default stripped names (no dashes and angles) are added to the return list
  • added support for quoted strings as arguments (thanks to @aniketschneider/issue #4)
  • added extra "\n" to --help output (thanks to @eddelbuettel)
  • added strip_names to docopt (suggestion of @eddelbuettel)
  • changed "Imports: methods"" into "Depends: methods" (thanks to @pschulam)

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.


0.7.1 by Edwin de Jonge, 2 years ago

Report a bug at

Browse source code at

Authors: Edwin de Jonge ([email protected])

Documentation:   PDF Manual  

MIT + file LICENSE license

Imports methods

Suggests testthat

Imported by orderly, prozor, qlcMatrix.

Suggested by httr2, littler, precommit, prrd.

See at CRAN