BiocManager icon indicating copy to clipboard operation
BiocManager copied to clipboard

return value of `BiocManager::install()`

Open lwaldron opened this issue 6 years ago • 4 comments

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?

lwaldron avatar Jan 21 '19 22:01 lwaldron

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.

mtmorgan avatar Jan 22 '19 09:01 mtmorgan

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.

lwaldron avatar Jan 22 '19 10:01 lwaldron

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.

dfeinzeig avatar Apr 12 '22 16:04 dfeinzeig

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.

hpages avatar Apr 12 '22 17:04 hpages