Skip to content

Instantly share code, notes, and snippets.

@lwaldron
Last active January 24, 2019 11:29
Show Gist options
  • Save lwaldron/3b002e72b4e99fc093f8dace4ab38bf6 to your computer and use it in GitHub Desktop.
Save lwaldron/3b002e72b4e99fc093f8dace4ab38bf6 to your computer and use it in GitHub Desktop.
Check which Bioconductor packages you can and can't install, with log
library(BiocManager)
dir.create("~/packagefiles")
unlink("installationresults.txt")
pkgs <- available.packages(contrib.url(BiocManager::repositories()["BioCsoft"]))
pkgs <- rownames(pkgs)
set.seed(1)
pkgs <- sample(pkgs)
## pkgs <- pkgs[!pkgs %in% installed.packages()]
installcheck <- function(x){
if (x %in% installed.packages())
return(TRUE)
BiocManager::install(x, ask=FALSE, update=FALSE, destdir="~/packagefiles")
success <- all(x %in% installed.packages())
return(success)
}
res <- rep(NA, length(pkgs))
names(res) <- pkgs
for (i in seq_along(pkgs)){
print(paste(c("Now installing package number", i, ":", pkgs[i]), collapse=" "))
res[i] <- installcheck(pkgs[i])
write.table(res[i], file="installationresults.txt", append=TRUE, col.names = FALSE)
}
@mtmorgan
Copy link

I guess https://gist.github.com/lwaldron/3b002e72b4e99fc093f8dace4ab38bf6#file-checkbiocinstallation-L24 can be vectorized as simply res <- logical(length(pkgs)); BiocManager::install(pkgs); res[pkgs %in% rownames(installed.packages())] <- TRUE which will likely be quite a bit faster (only a single call to discover what packages are available; a single calculation of dependencies, failure of a package to install means the package is downloaded only once rather than for each package depending on it, etc).

Also for what it's worth a pet peeve is https://gist.github.com/lwaldron/3b002e72b4e99fc093f8dace4ab38bf6#file-checkbiocinstallation-L23 where print() goes to stdout, but one wants to 'log' messages / diagnostic information to stderr using message(), warning(), or stop(). A secondary advantage of message() is that it does not require explicit paste() (except when using collapse=) so the line would be message("Now installing package number ", i, ": ", pkgs[i])

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment