Skip to content

[R-pkg-devel] Dependency needs to be loaded manually even its specified in the package

10 messages · Dirk Eddelbuettel, Joshua Ulrich, Nuria Perez-Zanon +2 more

#
Dear all,

I am maintaining a package call CSTools which is aimed for 
post-processing climate simulations.

The package is already published on CRAN with all dependencies correctly 
state in DESCRIPTION, NAMESPACE and roxygen2 headers.

However, when using one specific function which depends on 'qmap' 
package, I should loaded both packages by executing:

 ??? library(CSTools)
 ??? library(qmap)

In case I don't load the second library, I get the error

Error in doQmap(x = sample_cor, fobj = adjust, ...) :
 ? doQmap not defined for class(fobj) ==fitQmapQUANT

Has anyone an idea for needing to manually load a dependency? I provide 
a code below if someone wants to test it.

Thanks in advace,

N?ria

P.S.: Here is the code: library(CSTools) exp <- lonlat_data$exp
obs <- lonlat_data$obs
res <- CST_QuantileMapping(exp, obs)



http://bsc.es/disclaimer
#
On 18 September 2020 at 18:38, Nuria Perez-Zanon wrote:
| I am maintaining a package call CSTools which is aimed for 
| post-processing climate simulations.
[...]
|  ??? library(CSTools)
|  ??? library(qmap)

You never use library() in a package. Rather, you declare dependency
relationsships via DESCRIPTION (and likely NAMESPACE). See "Writing R
Extensions" for all the details.

Dirk
#
On Fri, Sep 18, 2020 at 11:56 AM Dirk Eddelbuettel <edd at debian.org> wrote:
And here's the relevant section:
https://cran.r-project.org/doc/manuals/r-release/R-exts.html#Registering-S3-methods

Best,
Josh

  
    
#
Hi Dirk,

Thanks for your comment. Maybe I haven't been enough clear. The package 
declares all the necessary dependencies correctly following the 
guidelines you provide. I am only able to detect the problem by running 
an example:

This works:

      library(CSTools)
  ??? library(qmap)
      exp <- lonlat_data$exp
     ?obs <- lonlat_data$obs
     ?res <- CST_QuantileMapping(exp, obs)

This fails:
      library(CSTools)
      exp <- lonlat_data$exp
     ?obs <- lonlat_data$obs
     ?res <- CST_QuantileMapping(exp, obs)

The DESCRIPTION sets:
Imports:
qmap,

The function sets:
|#'@import qmap|  

The NAMESPACE sets:
|import(qmap) I guess I am missing something to check but I don't know 
what. Thanks for your help. N?ria |

El 18/9/20 a las 18:52, Dirk Eddelbuettel escribi?:
http://bsc.es/disclaimer
#
Thanks, Jost. I don't know where to set this S3method(print, foo) but I 
will look at this in? depth.

Best,

N?ria

El 18/9/20 a las 18:57, Joshua Ulrich escribi?:
http://bsc.es/disclaimer
#
Hi N?ria,

I've never used qmap, but looking at the source code it seems it's not
using S3 or S4 methods in `doQmap()` but is looking for the proper method
using `exists()`. Given that your package doesn't import the required
function, it's not found by `exists()` and the `doQmap()` function
complains.

I think the only way around it is to declare the qmap package in the
Depends field, rather than the Imports field.

Best,
David

On Fri, Sep 18, 2020 at 9:39 AM Nuria Perez-Zanon <nuria.perez at bsc.es>
wrote:

  
  
#
Oooooh! Thanks, David. I was almost crazy. :D

I'll try it!

Best whishes,

N?ria

El 18/9/20 a las 19:07, David Kepplinger escribi?:
http://bsc.es/disclaimer
#
On 18/09/2020 12:38 p.m., Nuria Perez-Zanon wrote:
That's a design flaw in the doQmap function.  It looks like this:

function (x, fobj, ...)
{
     cc <- class(fobj)
     ffun <- substring(cc, 4, nchar(cc))
     ffun <- paste("do", ffun, sep = "")
     test <- sapply(ffun, exists, mode = "function")
     if (all(test)) {
         ffun <- match.fun(ffun)
     }
     else {
         stop("doQmap not defined for class(fobj) ==", class(fobj))
     }
     ffun(x, fobj, ...)
}

There are at least a couple of errors there:

- It appears to assume class(fobj) is a single element character string. 
  This wouldn't have caused your problem, but it will probably cause 
problems sometime..

- It tries to do something like S3 methods dispatch without using S3, by 
looking up "doQmapQUANT" in that line producing "test", but not saying 
where to look for it.  You could probably fix this by adding the envir 
argument to exists() in that call, e.g.

   test <- sapply(ffun, exists, mode = "function", envir = 
parent.env(environment()))

but it would be better to not try to invent a new object system.

Duncan Murdoch
#
On 18/09/2020 12:52 p.m., Dirk Eddelbuettel wrote:
I think you misread the post:  this was an example of code a user would 
run, not code from the package.

Duncan Murdoch
#
Thanks Duncan for look at this. I will avoid to invent a new object system.

Best,

N?ria

El 18/9/20 a las 19:13, Duncan Murdoch escribi?:
http://bsc.es/disclaimer