Skip to content
Prev 4259 / 12125 Next

[R-pkg-devel] [External] Re: Farming out methods to other packages

Thanks, Duncan. That's helpful.

In addition, I confess I had a closing parenthesis in the wrong place.
    Should be:    . . .   .GlobalEnv), silent = TRUE)

Cheers,

Russ

-----Original Message-----
From: Duncan Murdoch <murdoch.duncan at gmail.com> 
Sent: Saturday, August 10, 2019 2:43 PM
To: Lenth, Russell V <russell-lenth at uiowa.edu>; I?aki Ucar <iucar at fedoraproject.org>
Cc: r-package-devel at r-project.org
Subject: Re: [R-pkg-devel] [External] Re: Farming out methods to other packages
On 10/08/2019 3:27 p.m., Lenth, Russell V wrote:
That's a bad test:  class(object) might be a vector c("nomethod", "hasmethod").  You're only looking for recover_data.nomethod, and maybe only recover_data.hasmethod exists.

The getS3method() function won't automatically iterate through the class, you'll need to do that yourself, for example

S3methodOrDefault <- function(object, generic, default) {
   for (c in class(object)) {
     rd <- try(getS3method(generic, c, envir = .GlobalEnv, silent = TRUE))
     if (!inherits(rd, "try-error"))
       return(rd)
   }
   return(default)
}

used as

   S3methodOrDefault(object, "recover_data", internal_recover_data)

Duncan Murdoch