[R-pkg-devel] Calling registered C methods with a "variable name"
Ulrich Bodenhofer
bodenhofer at bioinf.jku.at
Mon Jul 3 18:14:19 CEST 2017
Hi,
As R CMD check is more pedantic about the registration of native
routines since version 3.4, I wanted to update my CRAN packages
accordingly. While this worked nicely for my 'apcluster' packages (and,
some time ago, for my Bioconductor packages), I am having problems with
my 'rococo' package. The problem is that I use string variables for some
of the .NAME arguments of the calls to the .Call() function. In other
word, the R function calling .Call() uses paste() to put together the
function name into a string and then calls .Call() with the .NAME
argument being this string variable. This is the simplest and most
efficient approach under the given circumstances (I omit a detailed
justification at this point, but I can provide it if wanted). Any other
approach would require a lot more coding. It is also safe, since the
variable part of the name is secured against invalid names using
match.arg() with a fixed list of options.
In more detail, here is a (slightly simplified) example: suppose there
are three C functions rcor_matrix_min, rcor_matrix_prod, and
rcor_matrix_lukasiewicz ...
dummy <- function(x, y, sim=c("min", "prod", "lukasiewicz"))
{
sim <- match.arg(sim)
...
funcName <- paste0("rcor_matrix_", sim)
result <- .Call(funcName, x, y)
...
}
The approach described above worked perfectly before I registered the
native routines rcor_matrix_min, rcor_matrix_prod, and
rcor_matrix_lukasiewicz. And it still works now with registered native
routines. The whole package also passes 'R CMD check' without errors,
warnings, or notes. However, if I add the option '--as-cran', I get a
bunch of notes saying that the symbol 'funcName' that I use as .NAME
argument is not registered. Can anybody comment on that please? Can I
simply ignore this? Is it imperative to fix this? Or is it an issue in
the 'R CMD check *** --as-cran' that this special case is simply overlooked?
Thanks in advance and best regards,
Ulrich
More information about the R-package-devel
mailing list