R: Set or Unset Environment Variables

Sys.setenv {base} | R Documentation

## Set or Unset Environment Variables

### Description

`Sys.setenv` sets environment variables (for other processes called from within R or future calls to `Sys.getenv` from this R process).

`Sys.unsetenv` removes environment variables.

### Usage

    Sys.setenv(...)

    Sys.unsetenv(x)

### Arguments

`...` | named arguments with values coercible to a character string.
`x` | a character vector, or an object coercible to character.

### Details

The names `setenv` and `putenv` come from different Unix traditions: R also has `Sys.putenv`, but this is now deprecated. The internal code uses `setenv` if available, otherwise `putenv`.

Non-standard R names must be quoted in `Sys.setenv`: see the examples. Most platforms (and POSIX) do not allow names containing `"="`.

There may be system-specific limits on the maximum length of the values of individual environment variables or of all environment variables.

### Value

A logical vector, with elements being true if (un)setting the corresponding variable succeeded. (For `Sys.unsetenv` this includes attempting to remove a non-existent variable.)

### Note

Not all systems need support `Sys.setenv` (although all known current platforms do) nor `Sys.unsetenv`. If `Sys.unsetenv` is not supported, it will at least try to set the value of the environment variable to `""`, with a warning.

### See Also

`Sys.getenv`, Startup for ways to set environment variables for the R session.

`setwd` for the working directory.

The help for ‘environment variables’ lists many of the environment variables used by R.

### Examples

    print(Sys.setenv(R_TEST="testit", "A+C"=123))  # `A+C` could also be used
    Sys.getenv("R_TEST")
    Sys.unsetenv("R_TEST")  # may warn and not succeed
    Sys.getenv("R_TEST", unset=NA)

[Package base version 2.8.1 Index]