From murdoch@dunc@n @end|ng |rom gm@||@com  Tue Jun 18 17:28:50 2019
From: murdoch@dunc@n @end|ng |rom gm@||@com (Duncan Murdoch)
Date: Tue, 18 Jun 2019 11:28:50 -0400
Subject: [Rd] Could generic functions check different S3 methods for an
 object when one of them produces an error?
In-Reply-To: <DB6PR02MB31272F107C5F54FE88D63B9592EB0@DB6PR02MB3127.eurprd02.prod.outlook.com>
References: <DB6PR02MB31272F107C5F54FE88D63B9592EB0@DB6PR02MB3127.eurprd02.prod.outlook.com>
Message-ID: <a4354681-7b29-e1b5-4703-9894183c03d5@gmail.com>

On 17/06/2019 3:56 a.m., IAGO GIN? V?ZQUEZ wrote:
> Hi,
> 
> 
> Let's say one has an object with multiple classes, and a generic function to apply to it has associated S3 methods for more than one of those classes. Further, the method it chooses (I do not know how; some order in the class vector?) is not the suitable one and it produces an error. Would there be some way to make the generic function to choice the correct method, or in case that for any method taken it produces an error, to try another one.
> 
> 
> For example (commented in detail here<https://github.com/tidymodels/broom/issues/714>):
> 
> 
> # object with multiple classes: the output of function `geepack::geeglm`. The output of `class(object)`:
> 
> ```
> 
> [1] "geeglm" "gee" "glm" "lm"
> 
> ```
> 
> The generic function: `stats::confint`.
> 
> The S3 method chosen: `confint.glm`. It produces an error. The correct method in this case would be `broom:::confint.geeglm`.

There is something wrong here.  If R knows about confint.geeglm (because 
broom is loaded, for example), then confint(x) should call it before it 
calls confint.glm.  It will look for methods confint.geeglm, then 
confint.gee, then confint.glm, then confint.lm.

However, when I run your code and load broom, I see

 > methods("confint")
[1] confint.default  confint.glm*     confint.lm       confint.lme* 
confint.lmList*  confint.nls*     confint.nlsList*
see '?methods' for accessing help and source code


(with no confint.geeglm shown).  So something is wrong, probably in 
broom.  As far as I can see, it never declares confint.geeglm as an 
S3method in its NAMESPACE file.  (I'm looking at the devel version in 
https://github.com/tidymodels/broom/blob/master/NAMESPACE).

Get that fixed, and your problem should go away.

Duncan Murdoch



[Rd] Could generic functions check different S3 methods for an object when one of them produces an error?
Duncan Murdoch