optparse-package: Command line option parser

Description Details Author(s) References See Also Examples

Description

Goal is to create an R package of a command line parser inspired by Python's “optparse” library.

Details

optparse is primarily intended to be used with “Rscript”. It facilitates writing “#!” shebang scripts that accept short and long flags/options. It can also be used from directly, but is probably less useful in this context.

See package vignette for a more detailed example.

Notes on naming convention in package: 1. An option is one of the shell-split input strings. 2. A flag is a type of option. a flag can be defined as having no argument (defined below), a required argument, or an optional argument. 3. An argument is a type of option, and is the value associated with a flag. 4. A long flag is a type of flag, and begins with the string “–”. If the long flag has an associated argument, it may be delimited from the long flag by either a trailing =, or may be the subsequent option. 5. A short flag is a type of flag, and begins with the string “-”. If a short flag has an associated argument, it is the subsequent option. short flags may be bundled together, sharing a single leading “"-"”, but only the final short flag is able to have a corresponding argument.

Author(s)

Trevor Davis.

Some documentation and unit tests ported from Allen Day's getopt package.

The documentation for Python's optparse library, which this package is based on, is Copyright 1990-2009, Python Software Foundation.

References

Python's optparse library, which this package is based on, is described here: http://docs.python.org/library/optparse.html

See Also

getopt

Examples

1
2
3
4
5
6
7
example_file <- system.file("exec", "example.R", package = "optparse")
   example_file_2 <- system.file("exec", "display_file.R", package = "optparse")
   ## Not run: 
       readLines(example_file)
       readLines(example_file_2)
   
## End(Not run)

optparse documentation built on May 2, 2019, 6:27 p.m.