Skip to content

[R-pkg-devel] [External] Re: S3 generic/method consistency warning for formula method

1 message · Smith, Brian J

#
That's an interesting solution too.

-----Original Message-----
From: Duncan Murdoch <murdoch.duncan at gmail.com> 
Sent: Friday, January 17, 2020 11:17 AM
To: Smith, Brian J <brian-j-smith at uiowa.edu>; r-package-devel at r-project.org
Subject: Re: [External] Re: [R-pkg-devel] S3 generic/method consistency warning for formula method
On 17/01/2020 10:59 a.m., Smith, Brian J wrote:
I think you can still do that, if your generic looks like this:

foo <- function(x, ...) {
   if (missing(x))
     UseMethod("foo", ..1)
   else
     UseMethod("foo")
}

and your methods look like this one:

foo.numeric <- function(x, ...) if (missing(x)) list(...) else list(x, ...)

There are some negatives to this solution:

  - it's more complicated than what you have
  - foo() now doesn't work unless you make it even more complicated
  - the name x is now special; foo("a", 1) will now dispatch to a different method than foo(w = "a", x = 1).  This is getting into the "world of hurt" that Joris mentioned.

The benefits are non-trivial:

  - It should make that warning go away
  - It doesn't depend on undocumented behaviour.

Duncan Murdoch