Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

return value of BiocManager::install() #39

Open
lwaldron opened this issue Jan 21, 2019 · 4 comments
Open

return value of BiocManager::install() #39

lwaldron opened this issue Jan 21, 2019 · 4 comments
Assignees

Comments

@lwaldron
Copy link

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?

@mtmorgan
Copy link
Collaborator

mtmorgan commented Jan 22, 2019

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.

@lwaldron
Copy link
Author

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.

@mtmorgan mtmorgan self-assigned this Jun 8, 2020
@dfeinzeig
Copy link

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.

@hpages
Copy link
Contributor

hpages commented Apr 12, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants