R package providing a command line optional and positional argument parser.
R
Permalink
Failed to load latest commit information.
R Remove name from argparse.R to remove cran note Oct 26, 2016
exec Move LICENSE into code Aug 24, 2013
inst Update copyrights through 2016 Oct 28, 2016
man
tests Support character vector for metavar in add_argument (closes #12, clo… Jul 26, 2016
vignettes
.Rbuildignore Add Travis CI integration and pip instructions to install rst2pdf (cl… Oct 4, 2015
.gitignore Add .gitignore Aug 24, 2013
.travis.yml
CONTRIBUTING Add a CONTRIBUTING file Feb 13, 2015
COPYING Move LICENSE back to COPYING Aug 29, 2013
DESCRIPTION Support character vector for metavar in add_argument (closes #12, clo… Jul 26, 2016
INSTALL Update documentation Apr 4, 2014
NAMESPACE Support character vector for metavar in add_argument (closes #12, clo… Jul 26, 2016
NEWS Support character vector for metavar in add_argument (closes #12, clo… Jul 26, 2016
README.rst Add Travis CI integration and pip instructions to install rst2pdf (cl… Oct 4, 2015

README.rst

argparse: Command line optional and positional argument parser.

CRAN Status Badge Build Status Coverage Status

A command line parser to be used with Rscript to write "#!" shebang scripts that gracefully accept positional and optional arguments and automatically generate usage.

To install the development version use the following command:

devtools::install_github("argparse", "trevorld")

dependencies

The package has a Python dependency. Read the INSTALL file for more information. Essentially the Python binary must have both the argparse and json modules which is are automatically included for Python 2.7 and Python 3.2+ and can be manually installed for Python 2.6 and Python 2.5.

Additionally this package depends on the R packages proto, findpython, getopt, and rjson.

To run the unit tests you will need the suggested R package testthat and in order to build the vignette you will need the suggested R package knitr (and knitr probably requires the system tool rst2pdf). rst2pdf should be installable via pip.:

sudo pip install rst2pdf

example

> parser <- ArgumentParser(description='Process some integers')
> parser$add_argument('integers', metavar='N', type="integer", nargs='+',
+                    help='an integer for the accumulator')
> parser$add_argument('--sum', dest='accumulate', action='store_const',
+                    const='sum', default='max',
+                    help='sum the integers (default: find the max)')
> parser$print_help()
usage: PROGRAM [-h] [--sum] N [N ...]

Process some integers

positional arguments:
  N           an integer for the accumulator

optional arguments:
  -h, --help  show this help message and exit
  --sum       sum the integers (default: find the max)

Default args for ArgumentParser()$parse_args are commandArgs(TRUE) which is what you'd want for an Rscript but not for interactive use:

> args <- parser$parse_args(c("--sum", "1", "2", "3"))
> accumulate_fn <- get(args$accumulate)
> print(accumulate_fn(args$integers))
[1] 6