A recurring question on SO is that package xx is not available for R version 2.xx.xx. For example the gplots
package requires the user to have R 3.0 installed in order for it to install. You can get older versions in the Archive of CRAN, but:
My question is the following: is there a more effective workflow in getting older package versions which match your older version of R? In the spirit of having different package repositories for different version of ubuntu.
I know one option would be to just get the latest version of R, but there might be some pressing reason to stick to a certain version of R. For example, one could be interested in repeating an old experiment which relies on an old version of R and support packages. Or one is limited by the system administration.
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. Note that if you are installing from source, you'll need to make sure you have the necessary toolchain to build packages from source.
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.
You only need to install packages the first time you use R (or after updating to a new version). **R Tip:** You can just type this into the command line of R to install each package. Once a package is installed, you don't have to install it again while using the version of R!
This is entirely untested (I'm running the latest version of R and have no time at the moment to install an old version of R to test it out), but perhaps one idea is to grab the dates from the "Archive" page for the package, compare that to the date for your R version, and progressively try installing the earlier versions, starting with the most recent version.
Something like this might be a starting point:
install_archive <- function(PackageName) {
if(!require("XML"))
install.packages("XML")
if(!require("devtools"))
install.packages("devtools")
rVersionDate <- as.Date(paste(R.Version()[c("year", "month", "day")],
collapse = "-"))
BaseURL <- "http://cran.r-project.org/src/contrib/Archive/"
u <- htmlParse(paste(BaseURL, PackageName, sep = ""))
doc <- readHTMLTable(u, skip.rows=1:2)[[1]][2:3]
releaseDate <- as.Date(strptime(doc$`Last modified`,
format="%d-%b-%Y"))
Closest <- which.min(rVersionDate -
releaseDate[releaseDate <= rVersionDate])
install_url(paste(BaseURL, doc$Name[Closest], sep = ""))
}
install_archive("reshape")
From here, I would add at least the following things to the function:
which.min()
line to rank()
, and try rank == 1, rank == 2, and so on, perhaps setting a maximum rank at which to try. Even so, this is a lot of "guess and check", only the software is doing the guessing and checking for you automatically. And, of course, the same advice holds that there is probably a good reason it's not on CRAN!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With