Multiple R Installations on Windows

I have written about how to install multiple versions of R on Linux. Now the time has come to Windows.

Installing different version of R on Windows is easy – just download the installer and choose an installation folder. If the bleeding edge on r-project is not the right version, then take a look at MRAN’s time machine.

I want the same “post installation” tweaks on both platforms:

I have not been able to make the “Linux way” with R environment variables work on Windows. Instead I rely on setting both things in the system-wide Rprofile.

I ue the default installation folder in Program Files. Here I consider R version 3.5.3 that is located in C:\Program Files\R\R-3.5.3.

The Rprofile is in C:\Program Files\R\R-3.5.3\library\base\R\Rprofile. Somewhere in the Rprofile the R environment variable R_LIBS_USER (the folder for user installed packages) is set:

               file.path(Sys.getenv("R_USER"), "R",
                               sub("\\..*$", "", R.version$minor),

The major and minor versions of R are available in R.version:

> R.version
platform       x86_64-w64-mingw32
arch           x86_64
os             mingw32
system         x86_64, mingw32
major          3
minor          5.3
year           2019
month          03
day            11
svn rev        76217
language       R
version.string R version 3.5.3 (2019-03-11)
nickname       Great Truth

The line sub("\\..*$", "", R.version$minor) strips the .3 from R.version and only retains the 5. Here I just skip the sub such that R_LIBS_USER is:

            Sys.getenv("R_USER"), "R",
            paste(R.version$major, R.version$minor, sep=".")

In the bottom of Rprofile I set the package repository:

options(repos = "")