Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Environment Variables in Rstudio on Mac

I have an environment variable that I can print from the terminal:

echo $STATTLE_TOKEN

returns

"ALKJSLKJLKFJALSKJFLASJFLSAF"

When I am in ipython, I can print it using:

import os
os.getenv("STATTLE_TOKEN")

which prints

"ALKJSLKJLKFJALSKJFLASJFLSAF"

However when I fire up a new Rstudio session,

Sys.getenv("STATTLE_TOKEN")

yields

""

What am I missing? I want to leverage my system's environment variables, but obviously I am not connecting the dots onto something. I would prefer not to have to put it in a file that loads on startup for my project.

Thanks in advance.

like image 913
Btibert3 Avatar asked Dec 08 '15 16:12

Btibert3


1 Answers

You probably start your interactive Python differently from your RStudio session. The outcome suggests that iPython may be a child process -- maybe you launched it from the shell?

The key will be to make R(Studio) aware of these environment variables. You could always set them explicitly in ${R_HOME}/etc/Renviron.site.

like image 103
Dirk Eddelbuettel Avatar answered Sep 25 '22 15:09

Dirk Eddelbuettel