Skip to content
Prev 3984 / 12125 Next

[R-pkg-devel] Three-argument S3method declaration does not seem to affect dispatching from inside the package.

Hi, Inaki,
On Sun, 2019-05-19 at 16:59 +0200, I?aki Ucar wrote:
f <- getS3method("foo","bar")
f(x) # spurious warning

foo.baz <- function(x) NextMethod("foo")
class(x) <- c("baz","bar")
foo(x) # spurious warning

Believe me, I spent a lot of time trying to get this to work, and I
tried even more sophisticated call stack alchemy, but people kept
getting false positives and negatives. (Take a look at my attempt in
the statnet.common package.)
Are you sure which package defines the generic matters? I've just ran
some tests with two packages and moving the generic around doesn't seem
to affect things: the calling function determines whose method is used.

It seems to me like there is no contradiction after all, except that I
propose that the registered method should take precedence within a
namespace.

The only situation in which it would change R's behaviour would be when
a package/namespace contains a function foo.bar() AND a NAMESPACE
containing S3method(foo,bar,not.foo.bar) AND calls foo() on objects of
type bar from inside the package. It is extremely unlikely to break any
existing code.

				Best,
				Pavel