Environment Variables in R Programming Language
Environment variables are a universal mechanism for conveying configuration information to Unix programs. Let’s look at how to set, get, and list environment variables in R.
Running the program shows that we pick up the value for FOO
that we set in the program, but that BAR
is empty.
The list of keys in the environment will depend on your particular machine.
If we set BAR
in the environment first, the running program picks that value up.
In R, environment variables are managed using the Sys.setenv()
and Sys.getenv()
functions. The Sys.getenv()
function without arguments returns all environment variables as a named character vector, which we can iterate over to get all keys.