Environment Variables in Rstudio on Mac

Bti*_*rt3 4 r environment-variables rstudio

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

echo $STATTLE_TOKEN
Run Code Online (Sandbox Code Playgroud)

returns

"ALKJSLKJLKFJALSKJFLASJFLSAF"
Run Code Online (Sandbox Code Playgroud)

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

import os
os.getenv("STATTLE_TOKEN")
Run Code Online (Sandbox Code Playgroud)

which prints

"ALKJSLKJLKFJALSKJFLASJFLSAF"
Run Code Online (Sandbox Code Playgroud)

However when I fire up a new Rstudio session,

Sys.getenv("STATTLE_TOKEN")
Run Code Online (Sandbox Code Playgroud)

yields

""
Run Code Online (Sandbox Code Playgroud)

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.

Dir*_*tel 5

您可能以与 RStudio 会话不同的方式启动交互式 Python。结果表明 iPython 可能是一个子进程——也许你是从 shell 启动它的?

关键是让 R(Studio) 知道这些环境变量。您始终可以在${R_HOME}/etc/Renviron.site.