add.argument | R Documentation |
Set the formal arguments of an ArgumentParser
.
## S4 method for signature 'essentials_ArgumentParser'
add.argument(..., action = NULL, nargs = NULL, constant, default,
type = "any", choices = NULL, required = NA, help = NA,
metavariable = NA, destination = NA, wrap = TRUE,
overwrite = getOption("essentials.overwrite", TRUE))
... |
character vector. A name for a positional argument or a set of flags for an optional argument. |
action |
character string. One of |
nargs |
number of arguments expected for this formal argument. A positive number specifying exactly the accepted number of arguments, two numbers specifying the range of the accepted number of arguments, or a character string indicating the accepted number of arguments, see Details. |
constant |
for action |
default |
object to be stored when this argument is not encountered. |
type |
character string naming an atomic mode or |
choices |
|
required |
logical. Is this argument required? |
help |
character vector. A brief description of the formal argument. |
metavariable |
character string. A name for the value in usage messages. |
destination |
character string. A name for the assigned value returned
by |
wrap |
logical. Should the usage message |
overwrite |
logical. If the name or flags are already in use, should they be replaced by this new definition? |
A positional argument is an argument in which the name of argument is not specified before its value (its value is assigned to the next available positional argument). The other types of arguments are arguments specified by a leading flag, either a short flag or a long flag.
action
is an instruction for what to do when this argument is found at
the command-line:
action = "store"
Stores the argument's value. When multiple values are provided, the last value is stored and the others are discarded.
action = "store_const"
If this argument is provided,
constant
is stored, otherwise default
is stored.
action = "store_true", "store_false"
Special cases of
action = "store_const"
in which constant = TRUE
,
default = FALSE
and constant = FALSE
,
default = TRUE
, respectively. default
can be overwritten
for special cases.
action = "append"
Stores the argument's value. When multiple values are provided, the values are appended and stored together.
action = "count"
Store the number of times this argument was provided.
action = "help"
Print the help message and exit the program.
action = "exit"
Print an exit message and exit the program.
action = "skip"
Skip the rest of the commmand line (the following arguments are for another program).
nargs
can be specified in three manners:
A positive number, the exact number of arguments that must be
provided. Specifying nargs
in this manner does not make sense with
action
"store_const"
, "store_true"
,
"store_false"
, and "count"
, or with action
"store"
when nargs
is greater than 1
, and will throw
a warning.
Two non-negative numbers, a lower and upper bound on the number of
arguments that must be provided. Specifying 0
as the lower bound
indicates no lower limit, and Inf
as the upper bound indicates no
upper limit.
A character string, specifically one of the regex
repetition quantifiers:
?
At most one argument.
*
Zero or more arguments.
+
One or more arguments.
{n}
Exactly n
arguments.
{n,}
At least n
arguments.
{n,m}
At least n
arguments, at most m
arguments.
When nargs
is NULL
, required
is used in its place.
Invisible NULL
.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.