An alternative to setRepositories() is use of (the CRAN package) 
BiocManager::install("gRbase") instead of install.packages(). BiocManager 
installs CRAN packages as well as Bioconductor packages.

Another, more transparent, solution is to use

  install.packages("gRbase", repos = BiocManager::repositories())

where the key idea is to include Bioconductor repositories explicitly. These 
approaches are preferred to  setRepositories(), because of the details of the 
twice-yearly Bioconductor release cycle, compared to the annual R release and 
patch cycles.

The usual approach to your problem is to move the package to Suggests:. But 
then the namespace commands like Imports, and the direct use of imported 
package functions, is not possible; you'll need to litter your code with fully 
resolved functions (graph::foo() instead of foo()). Also Suggests: is usually 
home to packages that have a limited role to play, but that does not seem 
likely for RBGL etc in your package.

Also, in implementing this approach one would normally check that the package 
were installed, and fail with an error message telling the user how to fix the 
problem (e.g., by installing the package). This doesn't really sound like 
progress. If you instead try to automatically install the package (in 
.onAttach(), I guess was your plan) you'll shortly run into users who need to 
use arguments to install.packages() that you have not made available to them.

Your CRAN page took me quickly to your package web site and clear installation 
instructions; I do not think use of Bioc packages is a particular barrier to 
use.

Martin Morgan

  

On 10/11/20, 2:52 PM, "R-help on behalf of Søren Højsgaard" 
<r-help-boun...@r-project.org on behalf of sor...@math.aau.dk> wrote:

    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
    S�ren





    .onAttach<-function(libname, pkgname) {

        ## package startup check
        toinstall=c(
            "graph",
            "Rgraphviz",
            "RBGL"
        )

        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(!base::all(already_installed)){
            if (!requireNamespace("BiocManager", quietly=TRUE))
                install.packages("BiocManager")
            BiocManager::install(toinstall[!already_installed], 
dependencies=TRUE)
        }
    }



        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to