Many Rs

Sometimes, you will want to run a script that uses groundhog in an older version of R.
This page explains why, and how to do it in Windows & Mac.

Why you may want to run older versions of R?

When using groundhog.library(pkg,date) you may want to use the R version available on that date for three reasons.

1.Speed: A package could install much faster in a previous version of R. e.g., the package dplyr_0.5.0, released in 2016,  takes about 15 minutes to install in R-4.0.0 but 2 minutes in R-3.3.2.
 Show explanation of speed difference.

Why older R packages take longer to install in newer versions of R?
When a package is first created it exists as a ‘source’ file, usually a .tar.gz file, or ‘tarball’, which can be installed on many operating systems and many R versions (possibly all of them). But these source-file tarballs can take a long time to install, as the computer needs to first use the tarball to create new files for the operating system and R version being used, and only then actually install it.  When that first process is finished, the computer has created a version of the package that is ready to be installed. That version is called a ‘binary’ (rather than ‘source’ file). When you install an older package in an older version of R, groundhog will download that ready-to-go ‘binary’, instead of the “source”.  The time gained is similar to copy-pasting the folders where a program is installed, vs installing a program from scratch. Copy pasting can be lots faster. 

2.Compatibility: On occasion, older versions of packages simply will not install in a newer version of R due to underlying incompatibilities. See example

For example the package igraph_0.7 is not compatible with current R versions. Maybe you never heard of igraph, but it is required by hundreds of other packages, none of which will install in current R versions if using a date for which igraph_0.7 was current, as their installation will stop when igraph_0.7 fails to install.

3.Reproducibility: The same script can give different results in newer versions of R See explanation

Every new version of R obviously introduces changes. Some of these changes will make older scripts, and packages, generate different results, or simply not run at all. For example, starting with R-3.6.0, the way in which seeds for random numbers are set was changed, thus scripts using set.seed() generate different results in R versions before vs after R-3.6.0 (.htm). Another example is that starting with R-4.0.0, the default for how strings are treated in data.frame() was changed (.htm), potentially breaking previous scripts and packages written and tested with previous versions of R.


How to install and run older version of R  


Instructions for Windows

Instructions for Windows

For Windows just two steps are needed to run scripts in older R versions.

Step 1. Install the R version(s) you need (these buttons download R from CRAN’s site in one click)
R-4.0.3 R-3.6.3 R-3.5.3 R-3.4.4 R-3.3.3 R-3.2.5 R-3.1.3 R-3.0.3

You may want to download all versions you don’t have, avoiding the need to come back here. Don’t forget to install (double click) the files you download.

Why ‘only’ these 8 versions? See explanation

Why not interim versions (e.g., 3.5.1, 3.5.2)
The R-version, e.g., 4.0.0,  has three numbers separated by a period. These version components are called ‘major’.’minor’.’patch’. Versions that differ only in the patch number, say 3.5.1 vs 3.5.3 differ only in a few small, well, ‘patches’, e.g.. fixed bugs, and minimally important new features. Unless your code happens to be affected by those small changes, for reproducibility purposes, it will not matter if you use 3.5.1 vs. 3.5.3. Therefore, if you use 3.5.3 for any script written with 3.5.x, you are not expected to have any problems.

Why not earlier versions (e.g., 2.2.1)
R Studio is not compatible with R<3.0.1, so we have not tested groundhog with those versions, but it probably does work for earlier R versions as well.

Step 2. Run R Studio with the version of R you want

Two ways to do this:

  • Start R Studio pressing down the CTRL Key when it starts, OR
  • Within R Studio: Tools → Global Options → “Change” next to top-right textbox

Instructions for Mac OS.

Instructions for Mac

Having multiple versions of R on a Mac takes a couple more steps than on a Windows computer. First, while R Studio has the option of choosing which R version to use in Windows, it does not on a Mac. The separate program RSwitch (.html), created by Bob Rudis, is needed. It switches which R version is used by R Studio. Second, when you install a new version of R in Windows the old one is kept, but on a Mac it is replaced by default; you need to change that default. 

You have two options to go about having many R versions on a Mac computer: (1) use our manyR installer, (2) install everything yourself step-by-step.

Option 1. (Simplest) Use our manyR installer
The installer will automatically install the main 8 versions of R (since R-3.0.3) and RSwitch (In total ~1 GBb fully installed) You need to download it, double click it, and wait ten minutes.

Download manyR installer.

Why 'only' 8 versions of R?

Only 8 versions for 2 reasons.

Reason 1. Interim versions are not included (e.g., 3.5.1, 3.5.2)
The R-version, e.g., 4.0.0,  has three numbers separated by a period. These version components are called ‘major’.’minor’.’patch’. Versions that differ only in the patch number, say 3.5.1 vs 3.5.3 differ only in a few small, well, ‘patches’, e.g.. fixed bugs, and minimally important new features. Unless your code happens to be affected by those small changes, for reproducibility purposes, it will not matter if you use 3.5.1 vs. 3.5.3. Therefore, if you use 3.5.3 for any script written with 3.5.x, you are not expected to have any problems.

Reason 2. Versions prior to release of R Studio (R-3.0.1) are not included
R Studio is not compatible with R<3.0.1, so we have not tested groundhog with those versions.

After the 10 minutes pass, go to your launchpad, click on RSwitch

And choose which R version you want to run by clicking the RSwitch icon on top of the screen:

Note: the manyR installer is written in golang; the full (simple) source code (i.e., before compilation) is publicly available as a .zip. The key file doing the installing (understandable even if you don’t know golang) is: main.go.

Option 2 - Do it yourself, step-by-step.


Step 1. Download the version of R you want to install

These buttons will directly download the indicated versions, for additional ones visit Mac’s CRAN page: https://cran.r-project.org/bin/macosx/

R-3.0.3 R-3.1.3 R-3.2.4 R-3.3.3 R-3.4.4 R-3.5.3 R-3.6.3 R-4.0.3

 

Step 2. Immediately before installing each version, run this command in terminal.

R Version Command to run in terminal prior to installing
R-3.0.3 sudo pkgutil –forget org.r-project.R.x86_64.fw.pkg
R-3.1.3 sudo pkgutil –forget org.r-project.R.x86_64.fw.pkg
R-3.2.4 sudo pkgutil –forget org.r-project.R.mavericks.fw.pkg
R-3.3.3 sudo pkgutil –forget org.r-project.R.mavericks.fw.pkg
R-3.4.4 sudo pkgutil –forget org.r-project.R.el-capitan.fw.pkg
R-3.5.3 sudo pkgutil –forget org.r-project.R.el-capitan.fw.pkg
R-3.6.3 sudo pkgutil –forget org.r-project.R.el-capitan.fw.pkg
R-4.0.3 sudo pkgutil –forget org.R-project.R.fw.pkg

Step 3. Install R Switch
To make sure it remains accessible, we have a copy of Version 1.7 on our server.zip
You can also obtain it from the RSwitch page directly: https://rud.is/rswitch/

Step 4. Run R Switch
Start-up R Switch in your launchpad, and you can switch to the R Version you want like this: