16

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:

  • It is not easy to see which version of the package you need to get for a specific R version.
  • You need to build the package from source, which is primarily a (mild) challenge under Windows.

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.

Community
  • 1
  • 1
Paul Hiemstra
  • 59,984
  • 12
  • 142
  • 149
  • 2
    that would be interesting. I'm working through a book on machine learning for R, and I've lost quite a bit of time due to my R and package versions being more recent. Some of the commands given in the book don't work for the more recent package versions. Would be good to "get R and packages as at a certain version" – TooTone Apr 18 '13 at 20:16
  • 2
    Its best if the authors show the version of R and the version of all packages used directly or indirectly in any analysis to allow it to be reproduced. – G. Grothendieck Apr 18 '13 at 23:33
  • Yes, ask a colleague to do all the lifting for you. :) – Roman Luštrik Apr 19 '13 at 05:42
  • 2
    You may be able to use `install_version` from `devtools`, or some modification of it – mnel Apr 19 '13 at 05:58

1 Answers1

4

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:

  • I would first try to install the most current version (not from the "Archive"), and if that fails, then move ahead.
  • In moving ahead, I would change the 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!

Thomas
  • 43,637
  • 12
  • 109
  • 140
A5C1D2H2I1M1N2O1R2T1
  • 190,393
  • 28
  • 405
  • 485
  • +1! I agree that without backwards support like e.g. Ubuntu has for older distributions, it will be hard to have an effective and robust means of running older versions of R. – Paul Hiemstra Apr 20 '13 at 05:52