arrg | R Documentation |
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.
arrg(name, ..., patterns = list(), header = NULL, footer = NULL)
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 |
A list with function elements
parse(args)
: Parse the character vector of arguments passed in, or by
default, the value of commandArgs(trailingOnly=TRUE)
.
show(con, width)
: Print a usage summary, detailing the valid options and
patterns. Text will be printed to the specified connection, default
stdout()
, and wrapped to the width given, which defaults to the value of
the standard width
option.
Jon Clayden
opt()
, pat()
# 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")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.