Installing older version of a package
In many situations when you install a new package, R will ask you whether you want to update a specific package in your library to the newest version. The main problem is sometimes in the updated version, a certain function might have been completely removed and thus could mess up your pre-existing code in use.
In this post, I will show how to install an old version of any package as long as it remains on CRAN.
First of all, I will demonstrate the issue with a package called “emmeans”. The package contains different functions for mean multiple comparisons. To date, the latest version of this package is 1.5.3 and was published on 9-Dec-2020. In the new version, CLD() function was removed. The authors/maintainer replaced it with a cld() from multcomp package. Although nothing major changed but for the objective of this post I will assume that we have to use the old CLD() with no alternative found.
Assuming you have already updated the emmeans package on your machine, the first thing to do is to remove the current (most recent) package.
remove.packages("emmeans")
To install a specific version of a package, we need to install a package called “remotes” and then load it from the library. Afterwards we can use install_version() by specifying the package name and version needed as shown below.
install.packages("remotes")
library(remotes)
install_version("emmeans", "1.4.5")
It is worth noting that the missing function from the updated version is likely replaced by either a new function by the authors/maintainer or they have provided an alternative and documented it in the latest version.