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ó:
On 18/09/2020 12:38 p.m., Nuria Perez-Zanon wrote:
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)
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
http://bsc.es/disclaimer
______________________________________________
R-package-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-package-devel