Skip to content
Prev 4895 / 12125 Next

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

I spoke too soon.  dotsMethods will not work for me since it does not allow for mixing of the ellipsis with other formal arguments.  For example, the following will not work if argument 'data' is not a formula; e.g. a data frame.

setGeneric("foo2", function(...) standardGeneric("foo2"))

setMethod("foo2", "formula",
  function(..., data) list(...)
)

What is the recommended course of action if the validity of an R CMD check warning is in doubt?  In this case, the warning message indicates an inconsistency that does not exist and references documentation that does not seem to explain the actual issue.

-----Original Message-----
From: R-package-devel <r-package-devel-bounces at r-project.org> On Behalf Of Smith, Brian J
Sent: Friday, January 17, 2020 11:45 AM
To: Joris Meys <Joris.Meys at UGent.be>; Duncan Murdoch <murdoch.duncan at gmail.com>; r-package-devel at r-project.org
Subject: Re: [R-pkg-devel] [External] Re: S3 generic/method consistency warning for formula method

Thanks for the tip about dotsMethods.  I am mainly working with S4 objects in my package, so that approach would fit well.  The following S4 method seems to work and pass R CMD checks.

setGeneric("foo2", function(...) standardGeneric("foo2"))

setMethod("foo2", "formula",
  function(...) list(...)
)

In my actual implementation of S3 methods, I do check that all ... elements are of the same class to avoid ending up in a world of hurt.  Converting them to S4 methods will save me from having to do those checks - nice!
Nevertheless, it looks like I have a way to get rid of the warning.

-----Original Message-----
From: Joris Meys <Joris.Meys at UGent.be>
Sent: Friday, January 17, 2020 10:12 AM
To: Smith, Brian J <brian-j-smith at uiowa.edu>; Duncan Murdoch <murdoch.duncan at gmail.com>; r-package-devel at r-project.org
Subject: Re: [R-pkg-devel] [External] Re: S3 generic/method consistency warning for formula method

Hi Brian,

I get what you want to do, but S3 isn't suited for that at all. If all elements in ... have to be the same class, you can use S4 (see ?dotsMethods). If not, then using S3 makes even less sense. Take following example:

x <- list()
y <- c(1,2)

foo(x,y) will dispatch to foo.list()
foo(y,x) will dispatch to foo.character()

You'll be in a world of hurt if you want to maintain or update that code. If you insist on using S3, you'll have to fix the position (and hence the name) of the argument you want to dispatch on.

my 2 cents
Cheers
Joris

--
Joris Meys
Statistical consultant

Department of Data Analysis and Mathematical Modelling Ghent University Coupure Links 653, B-9000 Gent (Belgium)
------------------------------

Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php
Message-ID: <SN6PR04MB43822C5FD6E8EAC2389C7A78B2310@SN6PR04MB4382.namprd04.prod.outlook.com>
In-Reply-To: <SN6PR04MB4382CF6211CDAD5A9EDE9E8FB2310@SN6PR04MB4382.namprd04.prod.outlook.com>