Code Monkey home page Code Monkey logo

docopt.r's Introduction

version downloads Build Status

docopt

docopt helps you to:

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

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.

Install

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

  • 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"

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"

Note

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.

docopt.r's People

Contributors

eddelbuettel avatar edwindj avatar ljos avatar pschulam avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.