Søren Højsgaard
2020-Oct-11 18:51 UTC
[R] Installing bioconduction packages in connection with loading an R package
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]]
Jeff Newmiller
2020-Oct-11 19:01 UTC
[R] Installing bioconduction packages in connection with loading an R package
This sounds like your package belongs in the bioconductor repository rather than in CRAN. Referencing bioc packages only in Suggests might make it appropriate for CRAN. On October 11, 2020 11:51:29 AM PDT, "S?ren H?jsgaard" <sorenh at 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]]-- Sent from my phone. Please excuse my brevity.
Bert Gunter
2020-Oct-11 19:48 UTC
[R] Installing bioconduction packages in connection with loading an R package
You would do better posting this on r-package-devel rather than here, I believe. Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) On Sun, Oct 11, 2020 at 11:51 AM S?ren H?jsgaard <sorenh at 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 at 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. >[[alternative HTML version deleted]]
Martin Morgan
2020-Oct-12 10:10 UTC
[R] Installing bioconduction packages in connection with loading an R package
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-bounces at r-project.org on behalf of sorenh at 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]]
Reasonably Related Threads
- improving the performance of install.packages
- improving the performance of install.packages
- issue with graph package in using RBGL -‘'graph' is not a valid installed package’"
- consider running tools::compactPDF(gs_quality = "ebook")
- consider running tools::compactPDF(gs_quality = "ebook")