arrg {arrg} | R Documentation |
Create an argument parser
Description
This function creates an argument parser that handles the specified options
and usage patterns. To parse arguments or display usage information, the
methods parse
or show
contained in the return value should be
called.
Usage
arrg(name, ..., patterns = list(), header = NULL, footer = NULL)
Arguments
name |
The name of the command. |
... |
Option specifications. See |
patterns |
A list of usage patterns that are valid for the command,
each specifying acceptable options and positional arguments. See |
header , footer |
Optional paragraphs of text to be prepended and/or
appended to the usage text produced by the |
Value
A list with function elements
-
parse(args)
: Parse the character vector of arguments passed in, or by default, the value ofcommandArgs(trailingOnly=TRUE)
. -
show(con, width)
: Print a usage summary, detailing the valid options and patterns. Text will be printed to the specified connection, defaultstdout()
, and wrapped to the width given, which defaults to the value of the standardwidth
option.
Author(s)
Jon Clayden
See Also
Examples
# A simple parser for a command called "test" with only one option, -h
p <- arrg("test", opt("h", "Print help"), patterns=list(pat(options="h!")))
# Print out usage information
p$show()
# Parse the option
p$parse("-h")