commandArgs

0th

Percentile

Extract Command Line Arguments

Provides access to a copy of the command line arguments supplied when this Rsession was invoked.

Keywords
programming
Usage
commandArgs(asValues=FALSE, excludeReserved=FALSE, excludeEnvVars=FALSE, os=NULL, ...)
Arguments
asValues
If TRUE, a named list is returned, where command line arguments of type --foo will be returned as
excludeReserved
If TRUE, arguments reserved by Rare excluded, otherwise not. Which the reserved arguments are depends on operating system. For details, see Appendix B on "Invoking R" in An Intro
excludeEnvVars
If TRUE, arguments that assigns environment variable are excluded, otherwise not. As described in R --help, these are arguments of format =.
os
A vector of character strings specifying which set of reserved arguments to be used. Possible values are "unix", "mac
...
Not used.
Details

This function should be fully backward compatible with the same function in the base package.

Value

  • Returns a character vector containing the names of the executable and the user-supplied command line arguments, or a list if asValue is TRUE. The first element is the name of the executable by which Rwas invoked. As far as I am aware, the exact form of this element is platform dependent. It may be the fully qualified name, or simply the last component (or basename) of the application. The attribute isReserved is a logical vector specifying if the corresponding command line argument is a reserved Rargument or not.

See Also

commandArgs(), Platform()

Aliases
  • commandArgs
Examples
# Get all arguments
  commandArgs()

  ## Spawn a copy of this application as it was invoked.
  ## system(paste(commandArgs(), collapse=" "))

  # Get only "private" arguments and not the name of the R executable.
  commandArgs(excludeReserved=TRUE)[-1]

  # If R is started as
  #   R DATAPATH=../data --args --root="do da" --foo bar --details --a=2
  # then commandArgs(asValue=TRUE) returns a list like
  #   list(R=NA, DATAPATH="../data" args=TRUE, root="do da", foo="bar", details=TRUE, a="2")
Documentation reproduced from package R.utils, version 0.7.9, License: LGPL version 2.1 or newer (the releases)

Community examples

Looks like there are no examples yet.