Why is RStudio getting environment variables from a non-activated conda environment?

RStudio Edition : Desktop
RStudio Version : RStudio 2023.06.1+524
OS Version      : Linux Mint 21
R Version       : 4.2.3 (2023-03-15) -- "Shortstop Beagle"

I understand that running RStudio in a conda environment is not supported. My question is about running RStudio on a system that happens to have Miniconda installed. Specifically, RStudio is adding one of the conda environments to the PATH and other environment variables.

I don't know why RStudio is picking this particular non-base conda environment out of the several I have on my computer, so it's a little hard to provide a reproducible example. A more general question may be "Where does RStudio get environment variables from?"

Environment variables

Below are differences in environment variables for R run at the command line, RStudio started from the launcher, and RStudio started at the command line.

CONDA_PREFIX

  • R CLI: /home/lee/miniconda3/envs/r
  • RStudio CLI: /home/lee/miniconda3/envs/py3.8-geo
  • RStudio launcher: /home/lee/miniconda3/envs/py3.8-geo

Various other CONDA_* environment variables

  • R CLI: various values
  • RStudio CLI: values that match R CLI
  • RStudio launcher: missing

PATH

  • R CLI: /home/lee/miniconda3/bin:/home/lee/miniconda3/condabin:/home/lee/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
  • RStudio CLI: /home/lee/miniconda3/condabin:/home/lee/miniconda3/envs/py3.8-geo/bin:/home/lee/miniconda3/bin:/home/lee/miniconda3/condabin:/home/lee/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/usr/lib/rstudio/resources/app/bin/quarto/bin:/usr/lib/rstudio/resources/app/bin/postback
  • RStudio launcher: /home/lee/miniconda3/condabin:/home/lee/miniconda3/envs/py3.8-geo/bin:/home/lee/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/usr/lib/rstudio/resources/app/bin/quarto/bin:/usr/lib/rstudio/resources/app/bin/postback

RETICULATE_PYTHON_FALLBACK

  • R CLI: missing
  • RStudio CLI: /home/lee/miniconda3/envs/py3.8-geo/bin/python
  • RStudio launcher: /home/lee/miniconda3/envs/py3.8-geo/bin/python

Various RSTUDIO_* environment variables

  • R CLI: missing
  • RStudio CLI: various values
  • RStudio launcher: various values

Differences in PATH Variables

The PATH variable seems to be constructed out of these four parts (in order):

  1. Present in RStudio CLI and RStudio launcher: /home/lee/miniconda3/condabin:/home/lee/miniconda3/envs/py3.8-geo/bin
  2. Present in R CLI and RStudio CLI: /home/lee/miniconda3/bin:/home/lee/miniconda3/condabin
  3. Present in all three: /home/lee/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
  4. Present in RStudio CLI and RStudio launcher: /usr/lib/rstudio/resources/app/bin/quarto/bin:/usr/lib/rstudio/resources/app/bin/postback

It makes sense that RStudio would adjust the path to add some specific RStudio resources (part 4). It does not make sense that RStudio is adding a random conda environment to the path to (part 1). I also don't understand why the path is different between RStudio started from the launcher and the CLI (part 2). In this case, it leads to one of the paths appearing twice when RStudio is started from the CLI.

I'm going to answer my own question here.

I had set the Python interpreter to a specific environment (py3.8-geo) in RStudio's Global Options. This changes several environment variables, as shown above, when running RStudio versus running R at the command line.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.