Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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