Last active
January 24, 2019 11:29
-
-
Save lwaldron/3b002e72b4e99fc093f8dace4ab38bf6 to your computer and use it in GitHub Desktop.
Check which Bioconductor packages you can and can't install, with log
This file contains hidden or 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(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) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 usingmessage()
,warning()
, orstop()
. A secondary advantage ofmessage()
is that it does not require explicitpaste()
(except when usingcollapse=
) so the line would bemessage("Now installing package number ", i, ": ", pkgs[i])