0

I am on Ubuntu 22.04. I am trying to create a new environment variable for R. In RStudio, I can see all the environment variables for R in RStudio terminal with the command:

printenv | grep ^R_

but the same doesn't work in a terminal outside of RStudio. I used

Sys.setenv(TMPDIR=/my/fav/path)

but it only persists for that R session. I tried using '.Renviron' file in my project folder as well but the attempt went in vain. Any help is appreciated. Thanks!

EDIT: I haven't been able to set any environment variable myself yet. I can only see them through the 'printenv' command in the terminal or 'Sys.getenv()' in R console. I am not sure where they are coming from.

  • 2
    How are you launching RStudio? Where are you setting the environment variable? See also: https://askubuntu.com/q/1186076/9287 – Konrad Rudolph Mar 30 '23 at 13:18
  • @KonradRudolph I am launching it via the app on Ubuntu. I haven't been able to set environment variables yet. But they only show up when I launch RStudio, and are not existent any other time. I cannot find if there is any file that is setting them whenever I launch RStudio. – Sanjiv Pradhanang Mar 30 '23 at 13:24
  • 2
    Ah, right, I got it the wrong way round. Yes, these environment variables are set *by R* when it starts, and are populated from various sources (including `~/.REnviron`). They are not set outside of R. If you want them to be set you need to explicitly set them yourself, e.g. in your `.bashrc` file or equivalent (depending on your shell). – Konrad Rudolph Mar 30 '23 at 13:28
  • @KonradRudolph Thank you, setting the TMPDIR variable in '.Renviron' in my root folder updated my 'R_SESSION_TMPDIR' accordingly. I had the '.Renviron' in the wrong place. – Sanjiv Pradhanang Mar 30 '23 at 13:36

0 Answers0