cmdArgs.RdSimple access to parsed command-line arguments.
cmdArgs(args=NULL, names=NULL, unique=TRUE, ..., .args=NULL)
cmdArg(...)A named list of arguments.
A character vector specifying the arguments to be
returned. If NULL, all arguments are returned.
If TRUE, only unique arguments are returned.
For cmdArgs(), additional arguments passed to
commandArgs(), e.g. defaults and always.
For cmdArg(), named arguments name and
default, where name must be a character string
and default is an optional default value (if not given,
it's NULL). Alternatively, name and default can
be given as a named argument (e.g. n=42).
(advanced/internal) A named list of parsed
command-line arguments.
cmdArgs() returns a named list with command-line arguments.
cmdArg() return the value of the requested command-line argument.
The value of each command-line argument is returned as a character
string, unless an argument share name with ditto in the (optional)
arguments always and default in case the retrieved
value is coerced to that of the latter.
Finally, remaining character string command-line arguments are
coerced to numerics (via as.numeric()), if possible,
that is unless the coerced value becomes NA.
Internally, commandArgs() is used.
args <- cmdArgs()
cat("User command-line arguments used when invoking R:\n")
#> User command-line arguments used when invoking R:
str(args)
#> Named list()
# Retrieve command line argument 'n', e.g. '-n 13' or '--n=13'
n <- cmdArg("n", 42L)
printf("Argument n=%d\n", n)
#> Argument n=42
# Short version doing the same
n <- cmdArg(n=42L)
printf("Argument n=%d\n", n)
#> Argument n=42