Environment Variables in RStudio on Mac
I recently asked a question on Stack Overflow on the best way to set environment variables on a Mac for use within an RStudio session.
It wasn’t as straightforward as I would have thought, so I wanted to share this quick post as a way to remind my future self of a quick way to solve the issue.
Generally, you can set environment variables by:
within a terminal. In a new session,
should yield what you need.
Within python, you can get at it by:
import os os.getenv("YOUR_VAR")
but if you are using
Sys.getenv("YOUR_VAR") will return
~, and create the
.Renviron file if it doesn’t already exist
cd ~ touch .Renviron open .Renviron
And in the file, type
Save the file and restart/reopen Rstudio.
Sys.getenv("YOUR_VAR") should be good to go.
For a more granular look at this functionality, feel free to reference the links below