11

I recently installed R 4.0, after previously using relying R 3.6.3. To manage R repositories, I use Rstudio (currently 1.2.5042 on a Windows 10 machine). After upgrading to R 4.0, I opened a project from a few months ago, and realized that Rstudio is now, by default, using the newer version of R (and it's library folder). When running renv::restore(), renv attempts to re-install all libraries in the .lock file for the newer version of R, and I don't see any way to specify that I want to keep using R 3.6.3 and it's associated library.

Coming from a python background, I had assumed that renv would create a virtual environment that isolates both the interpreter and the libraries that the project uses (similar to how anaconda environments are created). However, after looking through the documentation and doing a few searches, I have found no reference to isolating a particular version of R. I have, however, found that Rstudio defaults to using the latest version of R, which is not necessarily the behaviour that I want.

I have tried using anaconda to manage an R environment. However, Anaconda relies on its own smaller repository of R packages, and many of the libraries I need are from researchers that house their code on GitHub.

Is there a way to create an R environment in which I can isolate both the R libraries and the version of R itself? Or, perhaps there is something I am missing about how environments with R/Rstudio are intended to be used?

Matt
  • 238
  • 1
  • 8
  • You can change the version of R that Rstudio opens in Global Options. Would that work? There's a discussion about this here: https://github.com/rstudio/renv/issues/254 – Phil Jul 07 '20 at 20:23
  • Thank you for directing me to this discussion, Phil. It mirrors exactly my issue. From the answers provided, it seems like renv is not able to manage different versions of R. They list a few workarounds, including using a shell script, a docker-like r package (rocker), and a few other external options. I could change the global options, but with a single installation of Rstudio, it would be challenging to switch between projects, and challenging to share. If there are any other options, I'd be keen to hear them. – Matt Jul 08 '20 at 05:08

1 Answers1

7

You are correct that renv only manages the installed R packages, and not the R interpreter itself.

Depending on how you're using RStudio, you can still "fake" this by setting the RSTUDIO_WHICH_R environment variable. For example:

export RSTUDIO_WHICH_R=/path/to/R
rstudio

would tell RStudio to "bind" to the version of R specified by the RSTUDIO_WHICH_R environment variable.

For what it's worth, the ability to bind projects to a specific version of R is a feature of the professional editions of RStudio; however, it's not available in the open-source version. See here for more details.

Kevin Ushey
  • 20,530
  • 5
  • 56
  • 88