Learn R Programming

base (version 3.3)

commandArgs: Extract Command Line Arguments

Description

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

Usage

commandArgs(trailingOnly = FALSE)

Arguments

trailingOnly
logical. Should only arguments after --args be returned?

Value

  • A character vector containing the name of the executable and the user-supplied command line arguments. The first element is the name of the executable by which Rwas invoked. 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, or for an embedded Rit can be anything the programmer supplied.

    If trailingOnly = TRUE, a character vector of those arguments (if any) supplied after .

Details

These arguments are captured before the standard Rcommand line processing takes place. This means that they are the unmodified values. This is especially useful with the command-line flag to R, as all of the command line after that flag is skipped.

See Also

Startup #ifdef unix BATCH #endif

Examples

Run this code
commandArgs()
## Spawn a copy of this application as it was invoked,
## subject to shell quoting issues
## system(paste(commandArgs(), collapse = " "))

Run the code above in your browser using DataLab