When working on R projects, in order to have reproducible code the renv package is useful to create a lock file that lists all the packages, and their versions, that are used in the project. However, renv does not lock the version of R itself. Therefore, if you want to ensure that your code runs with a specific version of R, you may need to install and switch between multiple versions of R on your system.
To do this on linux (ubuntu), I used these three tutorials:
- How to install and switch between multiple R versions on a Mac
- Posit instructions to install an R version
- Posit switching between R versions
Following these instructions on a linux machine will allow you to have multiple R versions in the /opt/R
directory.
Then in order to open Rstudio with a certain R version in use. In terminal you need to run:
1
export RSTUDIO_WHICH_R=/opt/R/4.4.2/bin/R
and then in the same terminal session go to your R project file location and open your project file with the following command:
1
rstudio truncFVAR.Rproj