last update: 2022 07 14
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 Why older R packages take longer to install in newer versions of R? 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 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. 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) 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) Why not earlier versions (e.g., 2.2.1) Step 2. Run R Studio with the version of R you want Two ways to do this: 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 run a command line just before installing an additional version of R, so that your Mac does not delete the old one. 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) Reason 2. Versions prior to release of R Studio (R-3.0.1) are not included Note: the 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/ Step 2. Just before installing an R version, run a line in the terminal. When you start R installation on a Mac, one of the screens one usually ignores, actually tells you how to do this. For example, installing R-3.6.3 one of the screens you will be presented with reads: So at this point in the installation you open up the terminal and run the command line that the R installer tells you to run. Note that typically you will need to start with the word ‘sudo‘ when copy-pasting that line, see R screenshot vs command line above. Then you proceed with the installation of the R version you want. Step 3. Install R Switch For that you will need another program called RSwitch. We have a copy of Version 1.7 on our server.zip Step 4. Run R Switch Then you run R Studio and it will execute the version of R you selected on R Switch.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.
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.
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.
How to install and run older versions of R
Instructions for Windows
R-4.1.3
R-4.0.5
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
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.
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.
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.
R Studio is not compatible with R<3.0.1, so we have not tested groundhog
with those versions.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.
For R 3.6.3 that line would be:
sudo pkgutil --forget org.r-project.R.el-capitan.fw.pkg
At this point you have more than one version of R in your mac, but R Studio will not let you choose which you run.
You can also obtain it from the RSwitch page directly: https://rud.is/rswitch/
Start-up R Switch in your launchpad, and you can switch to the R Version you want like this:
[/expandsub6]