[R-pkg-devel] Checking package dependencies before loading namespace

Uwe Ligges ||gge@ @end|ng |rom @t@t|@t|k@tu-dortmund@de
Wed Sep 1 08:53:45 CEST 2021


Two more comments.

1. Note that your code only works in interactice mode, not when checking 
your package as it waits infinitely for the user's choice.

2. I do not see an advantage of installing BiocManager if EBImage is 
needed, the essential part is simply to select BioC as a repository to 
install packages from.

Best,
Uwe Ligges


On 31.08.2021 23:33, Duncan Murdoch wrote:
> People shouldn't be able to install your package unless the "hard" 
> dependencies are available.
> 
> If EBImage isn't essential to your package, you should make it a "soft" 
> dependency by listing it in Suggests and checking for it every time you 
> use it.
> 
> Duncan Murdoch
> 
> On 31/08/2021 3:20 p.m., Tiago Olivoto wrote:
>> Dear all,
>> I have a package called pliman 
>> <https://CRAN.R-project.org/package=pliman>
>> which depends on the Bioconductor package EBImage.
>>
>> When running install.packages("pliman") I get the following warning
>>
>> Warning in install.packages :  dependency ‘EBImage’ is not available
>>
>> and thus when loading the package with library(pliman), the following 
>> error
>> occurs
>>
>> Erro: package or namespace load failed for ‘pliman’ in loadNamespace(i,
>> c(lib.loc, .libPaths()), versionCheck = vI[[i]]):
>>   there is no package called ‘EBImage’
>>
>> I created a check function to check if EBImage is available and if 
>> not, ask
>> users if they want to install it
>>
>> ---
>> check_ebi <- function(){
>>    if(!requireNamespace("EBImage", quietly = TRUE)) {
>>      inst <-
>>      switch(menu(c("Yes", "No"), title = "Package {EBImage} required 
>> but not
>> available.\nDo you want to install it now?"),
>>             "yes", "no")
>>      if(inst == "yes"){
>>        if (!requireNamespace("BiocManager", quietly = TRUE)){
>>          install.packages("BiocManager")
>>        }
>>        BiocManager::install("EBImage", ask = FALSE, update = FALSE)
>>      } else{
>>        message("To use {pliman}, first install {EBImage} with
>> 'BiocManager::install(\"EBImage\")'.")
>>      }
>>    }
>> }
>> ---
>>
>> Is there any way to run this function prior to namespace loading? I tried
>> putting check_ebi() into .onLoad() but the same error occurs.
>>
>> Thanks in advance for any suggestions.
>> Tiago
>>
>>     [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> R-package-devel using r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-package-devel
>>
> 
> ______________________________________________
> R-package-devel using r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-package-devel



More information about the R-package-devel mailing list