R is an Open Source and there are constant updates happening. But sometimes you may need to install an older version of a package if the package has changed in a way that is incompatible with the version of R you have installed, or with your R code. You may also need to use an older version of a package if you are deploying an application to a location such as shinyapps.io, Shiny Server , or RStudio Connect where the environment may not allow you to run the latest version of the package or create a report in certain format.
Then you can install the older version of a R package in 2 ways :
1. Using install_versions() function from remotes package :
Let’s consider package dplyr & install version 0.8.5
install.packages('remotes')
library(remotes)
#Current Version Installed
packageVersion("dplyr")
[1] "1.0.4"
#Installing version 0.8.5
remotes::install_version("dplyr", version = "0.8.5")
#Check the installed version of the package
packageVersion("dplyr")
[1] ‘0.8.5’
If you know the URL to the package version you need to install, you can install it from source via install.packages() directed to that URL. If you don’t know the URL, you can look for it in the CRAN Package Archive.
If you’re on Windows or OS X and looking for a package for an older version of R (R 2.1 or below), you can check the CRAN binary archive.
2. Using versions package:
versions package simplifies this task considerably, for package versions released since 2014-09-17. It uses snapshots of the MRAN server at Microsoft R Open.
Microsoft R Open offers a downstream distribution of CRAN R packages known as MRAN, the Managed R Archive Network. The checkpoint server from Microsoft R Open takes a daily snapshot of the entire CRAN repository at precisely midnight UTC, and stores it on MRAN. These snapshots are available to the R community, and they allow users to access a package version from any exact date in the recent past.
The daily CRAN Repository Snapshots are available at the following URL:
https://cran.microsoft.com/snapshot/
Select the specific date you are looking for. For example:
https://cran.microsoft.com/snapshot/2017-03-15/
Use that URL as the repository when installing packages in R, as specified in the install.packages() function’s “repos” argument.
Example:
install.packages("dplyr", repos = "https://cran.microsoft.com/snapshot/2017-03-15/")
There are 4 functions in versions package that are useful :
1. installed.versions - show’s the current version of given package
install.packages("versions")
library(versions)
installed.versions('dplyr')
## [1] "0.8.5"
2. available.versions - show’s release dates and MRAN availability of any CRAN package
available.versions('dplyr')
## $dplyr
## version date available
## 1 1.0.4 2021-02-02 TRUE
## 2 1.0.3 2021-01-15 TRUE
## 3 1.0.2 2020-08-18 TRUE
## 4 1.0.1 2020-07-31 TRUE
## 5 1.0.0 2020-05-29 TRUE
## 6 0.8.5 2020-03-07 TRUE
## 7 0.8.4 2020-01-31 TRUE
## 8 0.8.3 2019-07-04 TRUE
## 9 0.8.2 2019-06-29 TRUE
## 10 0.8.1 2019-05-14 TRUE
## 11 0.8.0.1 2019-02-15 TRUE
## 12 0.8.0 2019-02-14 TRUE
## 13 0.7.8 2018-11-10 TRUE
## 14 0.7.7 2018-10-16 TRUE
## 15 0.7.6 2018-06-29 TRUE
## 16 0.7.5 2018-05-19 TRUE
## 17 0.7.4 2017-09-28 TRUE
## 18 0.7.3 2017-09-09 TRUE
## 19 0.7.2 2017-07-20 TRUE
## 20 0.7.1 2017-06-22 TRUE
## 21 0.7.0 2017-06-09 TRUE
## 22 0.5.0 2016-06-24 TRUE
## 23 0.4.3 2015-09-01 TRUE
## 24 0.4.2 2015-06-16 TRUE
## 25 0.4.1 2015-01-14 TRUE
## 26 0.4.0 2015-01-08 TRUE
## 27 0.3.0.2 2014-10-11 TRUE
## 28 0.3.0.1 2014-10-08 TRUE
## 29 0.3 2014-10-04 TRUE
## 30 0.2 2014-05-21 TRUE
## 31 0.1.3 2014-03-14 FALSE
## 32 0.1.2 2014-02-24 FALSE
## 33 0.1.1 2014-01-29 FALSE
## 34 0.1 2014-01-16 FALSE
3. install.versions - install specified versions of one or more packages
install.versions('dplyr', '1.0.0')
## package 'dplyr' successfully unpacked and MD5 sums checked
##
## The downloaded binary packages are in
## C:\Users\SANKHYA\AppData\Local\Temp\RtmpApDSXG\downloaded_packages
installed.versions('dplyr')
## [1] "1.0.0"
4. install.dates - install package versions available as of any specified date. It does the installation from the MRAN server via the standard install.packages function, so available binary versions can be installed instead of having to compile from source, and package dependencies as of the specified date can be included.
install.dates('dplyr', '2019-12-25')
## package 'dplyr' successfully unpacked and MD5 sums checked
##
## The downloaded binary packages are in
## C:\Users\SANKHYA\AppData\Local\Temp\RtmpApDSXG\downloaded_packages
installed.versions("dplyr")
## [1] "0.8.3"