[R] Installing bioconduction packages in connection with loading an R package

Søren Højsgaard @orenh @end|ng |rom m@th@@@u@dk
Sun Oct 11 20:51:29 CEST 2020

Dear all,

My gRbase package imports functionality from the bioconductor packages graph, Rgraphviz and RBGL.

To make installation of gRbase easy, I would like to have these bioconductor packages installed in connection with installation of gRbase, but to do so the user must use setRepositories() to make sure that R also installs packages from bioconductor.

Having to call setRepositories causes what can perhaps be called an (unnecessary?) obstacle. Therefore I have been experimenting with deferring installation of these bioc-packages until gRbase is loaded the first time using .onAttach; please see my attempt below.

However, if the bioc-packages are not installed I can not install gRbase so that does not seem to be a viable approach. (The bioc-packages appear as Imports: in DESCRIPTION).

Can anyone tell if it is a futile approach and / or perhaps suggest a solution. (I would guess that there are many CRAN packages that use bioc-packages, so other people must have faced this challenge before).

Thanks in advance.

Best regards

.onAttach<-function(libname, pkgname) {

    ## package startup check

    already_installed <- sapply(toinstall, function(pkg)
        requireNamespace(pkg, quietly=TRUE))

    if (any(!already_installed)){
        packageStartupMessage("Need to install the following package(s): ",
                              toString(toinstall[!already_installed]), "\n")

    ## install if needed
        if (!requireNamespace("BiocManager", quietly=TRUE))
        BiocManager::install(toinstall[!already_installed], dependencies=TRUE)

	[[alternative HTML version deleted]]

More information about the R-help mailing list