scribeArg-class {scribe} | R Documentation |
scribe argument
Description
ReferenceClass object for managing arguments
Details
The scribeArg class sets specifications and controls for how command line arguments are to be parsed. These are meant to be used in conjunction with scribeCommandArgs and specifically with the Rscript utility. However, a use can define their own scribeArg separately.
Fields
aliases
[character]
A vector to denote the argument's nameaction
[character]
An action for resolving the argument (seedefault
for note on using another scribeArg object)default
[ANY]
A default value. This can be another scribeArg object. When that is the case, the default value and action are pass through from the other scribeArg object.convert
[ANY]
Passed to theto
argument invalue_convert()
n
[integer]
The length of the valuesinfo
[character]
Additional information about the argument when printedoptions
[list]
A named list of options (see Options)positional
[logical]
Indicator if the argument is positional (i.e., not preceded by a-
or--
command line argument)resolved
[logical]
Has the object been resolvedvalue
[ANY]
The resolve valuestop
[character]
"none"
,"hard"
, or"soft"
execute
[function]
(For advanced use). Afunction
to be evaluated along with the arg. The function can have no parameters, a single parameter for the scribeArg object, or accept the scribeArg object as its first argument, and the scribeCommandArgs object as its second. Both objects will be passed by position
Methods
get_action()
Retrieve action
get_aliases()
Retrieve aliases
get_default()
Retrieve the default value
get_help()
Retrieve help information as a
character
vectorget_name(clean = TRUE)
Retrieve names
clean
When
TRUE
removes-
s from text
get_value()
Retrieve the resolved value
help()
Print out formatted help information
initialize( aliases = "", action = arg_actions(), default = NULL, convert = scribe_convert(), n = NA_integer_, info = NA_character_, options = list(), stop = c("none", "hard", "soft"), execute = invisible )
Initialize the scribeArg object
See fields for parameter information.
is_resolved()
Check if object has been resolved
Options
Several available options
action="list"
-
choices
-
An explicit set of values that argument must be. If the value parsed is not one of these, an error will occur.
action="flag"
-
no
-
When
TRUE
included appends--no
to aliases to invert results
Example:
With the argumentnew_arg("--test", options = list(no = TRUE))
, passing command arguments--test
would set this toTRUE
and--no-test
explicitly set toFALSE
.
See Also
Other scribe:
command_args()
,
new_arg()
,
scribeCommandArgs-class
Examples
# new_arg() is recommended over direct use of scribeArg$new()
# arguments with `--` indicators
new_arg("--verbose", action = "flag")
new_arg(c("-f", "--force"), action = "flag")
new_arg("--values", action = "list")
# positional
new_arg("verbose", action = "flag")
new_arg("value", action = "list", n = 1)
# special `...` action which absorbs left-over arguments
new_arg("values", action = "dots", info = "list of values")
new_arg("...", info = "list of values") # defaults when alias is "..."