BiocManager
BiocManager copied to clipboard
return value of `BiocManager::install()`
Having BiocManager::install()
return the "pkgs" argument is not especially useful. Could it instead return success/error codes? Otherwise, how can you tell in a script whether the requested packages were installed successfully or not?
Sounds pretty reasonable, though probably requiring a final step that consults installed packages to assess success. FWIW the behavior of BiocManager::install() is the same as biocLite(), and marginally better than install.packages (documented as returning NULL, invisibly).
I think I'd implement this along the lines of all(pkgs %in% rownames(installed.packages()))
. The endomorphism of BiocManager::install() makes this relatively compact
pkgs <- "sdfs"
ok <- BiocManager::install(pkgs) %in% rownames(installed.packages())
if (!all(ok))
...
I guess this fails when pkgs
are already installed, and the hope was to update them...
'For the user' (rather than for a robust package solution) in the scenario you describe one might use a calling handler to filter and continue after acceptable warnings
withCallingHandlers({
BiocManager::install(pkgs)
}, warning = function(w) {
## one package fails --> 'is not ...'; more than one 'are not...'
test <- any(grepl("not available", conditionMessage(w)))
if (test)
stop(w)
invokeRestart("muffleWarning")
})
Identifying only relevant warnings might be tricky, especially 'in general', because messages are translated to the locale of the system. One could stop on all warnings (but this is too stringent, with warnings for reasons other than failed package installation)
tryCatch(BiocManager::install(pkgs), warning = stop)
One would definitely want to arrive at a 'vectorized' solution with a single call to BiocManager::install() for several packages, because of the latency involved with checking and downloading individual packages.
Thanks Martin, I learned a few things from these solutions! The first one is adequate for my purposes, up to you whether the cost-benefit of implementing a conditional return value is worthwhile, noting these approaches in the documentation could also be a resolution. FWIW, there has been a similar discussion about install.packages()
on stackoverflow, with less satisfactory solutions.
Any update on this? As part of a build process I want to fail the build if installing a package fails (e.g., for missing system dependency). The logs clearly show the errors but I need to know that something failed.
Note that BiocManager::install(pkgs) %in% rownames(installed.packages())
can return false positives e.g. if a newer version of an installed package failed to install or if force=TRUE
was used but for some reason reinstalling the package failed.