How to set a variable in .Renviron

Check out ?Startup, but the usual way is to browse to your home directory on your computer, create a file called .Renviron then place your arguments in that. That way its available each time R starts, accessible using Sys.getenv().

The .Renviron file in your case would only read:

NOAA_KEY=your-noaa-token

..but I put loads of stuff in there, such as other API keys.

Its useful to keep out sensitive info out of your code, such as your token, which is why its probably preferred over the way you can also set it, Sys.setenv()

1 Like