cmdArgs
From R.utils v2.0.0
by Henrik Bengtsson
Simple access to parsed command-line arguments
Simple access to parsed command-line arguments.
- Keywords
- programming
Usage
cmdArgs(args=NULL, names=NULL, unique=TRUE, ..., .args=NULL)
cmdArg(...)
Arguments
- args
- A named
list
of arguments. - names
- A
character
vector
specifying the arguments to be returned. IfNULL
, all arguments are return - unique
- If
TRUE
, only unique arguments are returned. - ...
- For
cmdArgs()
, additional arguments passed tocommandArgs
(), e.g.defaults
andalways
. ForcmdArg()
, named argumentsname
and - .args
- (advanced/internal) A named
list
of parsed command-line arguments.
Value
cmdArgs()
returns a namedlist
with command-line arguments.cmdArg()
return the value of the requested command-line argument.
Coercing to non-character data types
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 numeric
s (via as.numeric
()), if possible,
that is unless the coerced value becomes NA
.
See Also
Internally, commandArgs
() is used.
Examples
args <- cmdArgs()
cat("User command-line arguments used when invoking R:
")
str(args)
# Retrieve command line argument 'n', e.g. '-n 13' or '--n=13'
n <- cmdArg("n", 42L)
printf("Argument n=%d
", n)
# Short version doing the same
n <- cmdArg(n=42L)
printf("Argument n=%d
", n)
Community examples
Looks like there are no examples yet.