Skip to content
Prev 2876 / 12125 Next

[R-pkg-devel] Weird error on CRAN linux check

I see that you realized it was Inaki who gave you he patch, not me :-)

I've been looking into this further, and the toy example David put up is
actually not the right one to look at. In that example the generic is
created in the namespace.  But in the original huxtable that was not the
case. Try the following :

foo.barrista <- function(x, ...){
  cat("In barrista\n")
}

make_a_method <- function (x){
  assign("foo", function(x, ...){
    UseMethod("foo")
  } ,envir = getNamespace('testMethod'))

  assign("foo.bar", function (x, ...) cat("In foo.bar"),
         envir = getNamespace('testMethod'))
}
make_a_method()

With a namespace:

S3method(foo,bar)
S3method(foo,barrista)
export(foo)

And test code :

thebar <- structure(1, class = c("bar", "data.frame"))
thebarrista <- structure(1, class = "barrista")

foo(thebarrista)
foo(thebar)

In both cases the correct method cannot be found. When the methods are both
exported and registered (i.e. add export(foo.bar) and export(foo.barrista)
to NAMESPACE), everything goes fine again on Windows.I went back to the
original version you sent to CRAN, and that doesn't cause any problems on
Windows either. So when the methods are exported and registered, the
problem apparently only exists on Linux.

The other thing I've noticed, is that align() is called from within the
function huxtable() without problem. So the method is found when the
generic is called by a function in the namespace, but not when the generic
is called from the global env. The patch of Inaki makes sure that the
_generic_ is assigned in the namespace itself instead of a child
environment.

To the previous minimal example, add:

baz <- function(x) foo(x)

and to the NAMESPACE:

export(baz)

If you try now:

baz(thebar)
baz(thebarrista)

the correct methods are found. But foo(thebar) etc still doesn't find the
correct ones.

On a sidenote: roxygen is really not helping here. @export literally
exports all these methods as they're not recognized as S3methods. So here
you actually need the deprecated tag @S3method. I wish Hadley would revert
the deprecation, as @export fails to recognize S3 methods correctly in
other cases as well.


On Thu, Jul 5, 2018 at 1:19 PM, Duncan Murdoch <murdoch.duncan at gmail.com>
wrote: