Sys.getenv
Get Environment Variables

Description

Returns the values of environment variables.

Usage


Sys.getenv(x = NULL, unset = "", names = NA) 

Arguments

x a vector of character strings giving the names of the environment variables whose values are sought.

In UNIX, by convention, environment variable names are specified using upper-case letters. In Windows, environment variable names are case-insensitive. If x is missing, the entire environment is returned.

unset a character string. Displayed when the request contains an environment name that is not set. By default, "".
names a logical value or NA.
  • If TRUE, the names attribute is included in the return value.
  • If FALSE, the names attribute is excluded from the return value.
  • If NA (the default), the names attribute is included in the return value when x is missing, or if there is more than one element in x. Otherwise, the names attribute is excluded from the return value.
Value
returns a vector of character strings giving the values of the environment variables named in x, or the values of all environment variables if x is omitted. If an element of x is not the name of an environment variable, the corresponding element of the returned vector is the null string ("") by default.
Depending on the value of the names argument, the returned vector either has or does not have a names attribute that holds the variable names.
Background
the engine uses several environment variables, such as those in the example section.
This function can be used to retrieve the value of any environment variable, not just those set by the engine.
The Sys.getenv function replaces getenv, which was used in S-PLUS and R.
Examples
Sys.getenv("HOME") 
Sys.getenv("S_PRINT_ORIENTATION") # might return "landscape" (on Unix) 
shome <- "SHOME" 

# returns character string of the home directory Sys.getenv(shome) all.env <- Sys.getenv() # whole environment leading.S <- grep("^S", names(all.env)) # index into all.env for those names starting with 'S' all.env[leading.S] # values of these variables; names are preserved Sys.getenv(c("SHOME", "S_FIRST")) Sys.getenv()[c("SHOME", "S_FIRST")]

Sys.getenv("a", unset = "not set") # # "not set" Sys.getenv(names = FALSE) # list all environment variables without names. Sys.getenv("HOME") # no names attribute Sys.getenv(c("HOME", "FOO")) # with names attribute

Package base version 6.1.1-7
Package Index