4

I'm looking at install.packages and I don't see any option to specify a particular version. Is there a way? I was hoping to find something like install.packages(c('xts'),version='0.9.3')

I found this answer: https://stackoverflow.com/a/12679452/841830 However, after installing devtools, I did:

library(devtools)
install_version('xts','0.9.3')

It gave this error message:

Error in url(sprintf("%s/src/contrib/Archive.rds", repos), "rb") : 
  cannot open the connection
In addition: Warning message:
In url(sprintf("%s/src/contrib/Archive.rds", repos), "rb") :
  cannot open: HTTP status was '404 Not Found'
3: url(sprintf("%s/src/contrib/Archive.rds", repos), "rb")
2: gzcon(url(sprintf("%s/src/contrib/Archive.rds", repos), "rb"))
1: install_version("xts", "0.9.3")

(Using "0.9-3", hyphen instead of dot, gives same error.)

Background: I have a regression in an xts rollapply function call, since upgrading from 0.9.3 to 0.9.4. However when I looked in the online svn repository, there appears to have been no change since I know it last worked. So I want to install 0.9.3 (and then 0.9.2, etc.) to confirm exactly when the problem was introduced.

Community
  • 1
  • 1
Darren Cook
  • 27,837
  • 13
  • 117
  • 217
  • 1
    The problem is caused by `na.fill.zoo`, so you won't find it by looking in past xts packages. Try using the latest zoo on R-Forge and see if that fixes the issue. – Joshua Ulrich Jun 10 '13 at 13:06

2 Answers2

4

Right now the function install_version seems to have several problems with the current CRAN archive and you already identified the first two:

  1. The hyphen in 0.9-3 is replaced by a dot.
  2. The file src/contrib/Archive.rds could not be found (it moved to src/contrib/Meta/archive.rds on CRAN).
  3. The format of archive.rds changed apparently.

I sent a pull request with fixes for these problems, so it should be fixed soon in devtools. If you want to use install_version in the meantime, load library devtools but use this slightly edited function:

install_version <- function(package, version = NULL, repos = getOption("repos"), type = getOption("pkgType"), ...) {

  contriburl <- contrib.url(repos, type)
  available <- available.packages(contriburl)

  if (package %in% row.names(available)) {
    current.version <- available[package, 'Version']
    if (is.null(version) || version == current.version) {
      return(install.packages(package, repos = repos, contriburl = contriburl,
        type = type, ...))
    }
  }

  con <- gzcon(url(sprintf("%s/src/contrib/Meta/archive.rds", repos), "rb"))
  on.exit(close(con))
  archive <- readRDS(con)

  info <- archive[[package]]
  if (is.null(info)) {
    stop(sprintf("couldn't find package '%s'", package))
  }

  if (is.null(version)) {
    # Grab the latest one: only happens if pulled from CRAN
    package.path <- info[length(info)]
  } else {
    package.path <- paste(package, "/", package, "_", version, ".tar.gz",
      sep = "")
    if (!(package.path %in% row.names(info))) {
      stop(sprintf("version '%s' is invalid for package '%s'", version,
        package))
    }
  }

  url <- paste(repos, "/src/contrib/Archive/", package.path, sep = "")
  install_url(url, ...)
}
1

If all else fails, you can get the source from CRAN directly: http://cran.r-project.org/src/contrib/Archive/xts/xts_0.9-3.tar.gz

Hong Ooi
  • 56,353
  • 13
  • 134
  • 187
  • Thanks. `wget http://cran.r-project.org/src/contrib/Archive/xts/xts_0.9-3.tar.gz` followed by `R CMD INSTALL xts_0.9-3.tar.gz` worked. – Darren Cook Jun 10 '13 at 04:54