I have a package metagam
which is on CRAN, and it passes all of CRAN's automated tests. However, the package depends on the Bioconductor package multtest
through the chain of dependencies metagam
<- metap
<- mutoss
<- multtest
. This is visualized below for the dependencies of the metap
package.
# Code for creating dependency graph
library(miniCRAN)
plot(makeDepGraph("metap", suggests = FALSE))
The answer to this question suggests adding biocViews:
to DEPENDENCIES
. Accordingly, the relevant parts of my DESCRIPTION
look like this:
biocViews:
Imports:
dplyr,
furrr,
ggplot2,
knitr,
metafor,
metap,
purrr,
rlang,
stringr,
tidyr
RoxygenNote: 7.1.0
Suggests:
future,
mgcv,
gamm4,
gratia,
roxygen2,
rmarkdown,
devtools,
covr,
viridis,
testthat (>= 2.1.0)
However, adding biocViews
appears to only work for first-order dependencies. In my case, there are no Bioconductor packages listed in DESCRIPTION
, and hence automatic package installation fails. This is shown by the example below.
# Remove packages 'metap', 'mutoss', and 'multtest' if they are installed
# If, any of these are installed, the dependency 'multtest' will not be attempted to be installed
pkgs <- installed.packages()[, "Package", drop = TRUE]
if("metap" %in% pkgs) remove.packages("metap")
#> Removing package from '/Library/Frameworks/R.framework/Versions/4.0/Resources/library'
#> (as 'lib' is unspecified)
if("mutoss" %in% pkgs) remove.packages("mutoss")
#> Removing package from '/Library/Frameworks/R.framework/Versions/4.0/Resources/library'
#> (as 'lib' is unspecified)
if("multtest" %in% pkgs) remove.packages("multtest")
# Install 'metagam', which trigges installation of the dependency 'metap'
# The dependencies are 'metagam' <- 'metap' <- 'mutoss' <- 'multtest'
install.packages("metagam")
#> Warning: dependency 'multtest' is not available
#> also installing the dependencies 'mutoss', 'metap'
#>
#> The downloaded binary packages are in
#> /var/folders/sz/q9lc1ggd66n5k5x_yp094hgh0000gn/T//Rtmphvg646/downloaded_packages
Created on 2020-06-20 by the reprex package (v0.3.0)
Furthermore, this causes the package to fail, because the dependency on multtest
is real:
# The code below is from the examples of the metagam::metagam() function
# The last line fails because the dependency 'multtest' is not available
library(metagam)
library(mgcv)
#> Loading required package: nlme
#> This is mgcv 1.8-31. For overview type 'help("mgcv-package")'.
## Create 5 datasets
set.seed(1234)
datasets <- lapply(1:5, function(x) gamSim(scale = 5, verbose = FALSE))
## Fit a GAM in each dataset, then use strip_rawdata() to remove
## individual participant data
models <- lapply(datasets, function(dat){
## This uses the gam() function from mgcv
model <- gam(y ~ s(x0, bs = "cr") + s(x1, bs = "cr") + s(x2, bs = "cr"), data = dat)
## This uses strip_rawdata() from metagam
strip_rawdata(model)
})
## Next, we meta-analyze the models.
## It is often most convenient to analyze a single term at a time. We focus on s(x1).
meta_analysis <- metagam(models, terms = "s(x1)", grid_size = 30)
#> Error in loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]]): there is no package called 'multtest'
Created on 2020-06-20 by the reprex package (v0.3.0)
I know I can inform the users, either on the GitHub repository or via a startup message, that they need to run the following lines before attempting to install metagam
, but it does not provide the best user experience.
if (!requireNamespace("BiocManager", quietly = TRUE))
install.packages("BiocManager")
BiocManager::install("multtest")
What seems to me as the solution, is adding multtest
to Imports. However, wouldn't this give a warning about unused imports, since no functions from multtest
is directly used by metagam
, but rather through the chain of dependencies specified above. I could not create such a warning on my own system, running R CMD check --as-cran
, so maybe CRAN is fine with this? Alternatively, I could add a line of code somewhere using multtest
, but this seems very hacky.
To summarize, my question is what I should do for the multtest
package to be automatically installed when metagam
is installed.
Because Bioconductor has twice-yearly releases, and this differs from CRAN release practices, the 'right' thing to do is to use Bioconductor tools to install your package, so BiocManager::install("metap")
. It does not matter that metap is a CRAN package. BiocManager installs the correct version of the Bioconductor package for the user's version of R.
If this solution isn't palatable, then the next-best right thing to do is to adjust your dependencies to avoid direct or indirect dependencies on Bioconductor packages.