commandArgs             package:R.utils             R Documentation

_E_x_t_r_a_c_t _C_o_m_m_a_n_d _L_i_n_e _A_r_g_u_m_e_n_t_s

_D_e_s_c_r_i_p_t_i_o_n:

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

_U_s_a_g_e:

     commandArgs(asValues=FALSE, excludeReserved=FALSE, excludeEnvVars=FALSE, os=NULL, ...)

_A_r_g_u_m_e_n_t_s:

asValues: If 'TRUE', a named 'list' is returned, where command line
          arguments of type '--foo' will be returned as 'TRUE' with
          name 'foo', and arguments of type '-foo=value' will be
          returned as 'character' string 'value' with name 'foo'. In
          addition, if '-foo value' is given, this is interpreted as
          '-foo=value', as long as 'value' does not start with a double
          dash ('--').

excludeReserved: If 'TRUE', arguments reserved by R are excluded,
          otherwise not. Which the reserved arguments are depends on
          operating system. For details, see Appendix B on "Invoking R"
          in _An Introduction to R_.

excludeEnvVars: If 'TRUE', arguments that assigns environment variable
          are excluded, otherwise not. As described in 'R --help',
          these are arguments of format <key>=<value>.

      os: A 'vector' of 'character' strings specifying which set of
          reserved arguments to be used. Possible values are '"unix"',
          '"mac"', '"windows"', '"ANY"' or '"current"'. If '"current"',
          the current platform is used. If '"ANY"' or 'NULL', all three
          OSs are assumed for total cross-platform compatibility.

     ...: Not used.

_D_e_t_a_i_l_s:

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

_V_a_l_u_e:

     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 R was
     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 R argument or
     not.

_A_u_t_h_o_r(_s):

     Henrik Bengtsson (<URL: http://www.braju.com/R/>)

_S_e_e _A_l_s_o:

     'commandArgs'(), 'Platform'()

_E_x_a_m_p_l_e_s:

       # 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")

