Skip to content

Instantly share code, notes, and snippets.

@rmflight
Last active July 7, 2016 19:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rmflight/f3d6d1982e707350606e to your computer and use it in GitHub Desktop.
Save rmflight/f3d6d1982e707350606e to your computer and use it in GitHub Desktop.
updating full set of installed packages in R
# list of github installed packages
#gitPackages <- list(c("devtools", "hadley"),
# c("samatha", "DASpringate"),
# c("twitteR", "geoffjentry"))
# Other specific things
# list of local packages
localPackages <- c("~/Projects/work/rmfNotifier")
# get previous set of installed packages
oldLib <- "/home/rmflight/R-322-bioc-31-libs"
newLib <- "/home/rmflight/R-331-bioc-33-libs"
allInstalled <- installed.packages(oldLib)
newInstalled <- installed.packages(newLib)
if (length(list.files(newLib)) > 0){
tryInstall <- setdiff(rownames(allInstalled), rownames(newInstalled))
} else {
tryInstall <- rownames(allInstalled)
}
# get the dependencies
allDeps <- tools:::package_dependencies(tryInstall, db = allInstalled)
nDep <- vapply(allDeps, function(x){
retVal <- 0
if (!(is.null(x))){
retVal <- length(x)
}
retVal
}, double(1))
nDep <- sort(nDep, decreasing = FALSE)
toInstall <- names(nDep)
cranRepo <- "https://cran.rstudio.com/"
cranAvailable <- available.packages(contrib.url(cranRepo))
isCran <- toInstall[toInstall %in% rownames(cranAvailable)]
for (package in isCran){
install.packages(package, repo=cranRepo, lib = newLib)
wasInstalled <- toInstall %in% rownames(installed.packages(newLib))
}
biocRepos <- c("https://bioconductor.org/packages/3.3/bioc/src/contrib",
"https://bioconductor.org/packages/3.3/data/experiment/src/contrib",
"https://bioconductor.org/packages/3.3/data/annotation/src/contrib",
"https://bioconductor.org/packages/3.3/extra/src/contrib")
biocAvailable <- available.packages(biocRepos)
isBioc <- toInstall[toInstall %in% rownames(biocAvailable)]
for (package in isBioc){
install.packages(package, contriburl = biocRepos, lib = newLib)
wasInstalled <- toInstall %in% rownames(installed.packages(newLib))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment