Skip to content

Instantly share code, notes, and snippets.

@MattNapsAlot
Created October 6, 2012 16:44
Show Gist options
  • Save MattNapsAlot/3845435 to your computer and use it in GitHub Desktop.
Save MattNapsAlot/3845435 to your computer and use it in GitHub Desktop.
bug-fixed version of Hadley Wickham's install_version() method from the devtools package
library(devtools)
install_version <- function (package, version = NULL, repos = getOption("repos"),
type = getOption("pkgType"), ...)
{
contriburl <- contrib.url(repos, type)
available <- available.packages(contriburl)
## converting the version to numeric breaks packages that use dashes in their version numbers
# if (!is.null(version)) {
# version <- numeric_version(version)
# }
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/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)) {
package.path <- info[length(info)]
}
else {
package.path <- paste(package, "/", package, "_", version,
".tar.gz", sep = "")
if (!(package.path %in% info)) {
stop(sprintf("version '%s' is invalid for package '%s'",
package, version))
}
}
url <- paste(repos, "/src/contrib/Archive/", package.path,
sep = "")
install_url(url, ...)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment