Created
October 6, 2012 16:44
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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