Re: [R] How to find S4 generics?

From: Spencer Graves <spencer.graves_at_pdf.com>
Date: Thu 20 Jul 2006 - 08:23:58 EST

Hi, Thomas: Thanks very much. I haven't tried it yet, but it looks very useful. Best Wishes, Spencer Graves

Thomas Lumley wrote:
> On Wed, 19 Jul 2006, Spencer Graves wrote:

>> 	  Am I correct then that the 'methods' function could, at least
>> theoretically, be revised so methods(class=...) could identify both S3
>> and S4 methods (ignoring inheritance, as it does now, I believe)?
>>

>
> Here is a function to find methods for a formal class. It returns a list
> with elements corresponding to a generic, and each element is a list of
> strings showing all the signatures that contain any of the specified
> classes.
>
> If super=TRUE it looks at all superclasses, if ANY=TRUE it also returns
> methods for ANY class.
>
> If you have lme4 loaded, try
> methods4("lmer"
> methods4("ddiMatrix")
> methods4("ddiMatrix",super=TRUE)
>
> -thomas
>
> methods4<-function(classes, super=FALSE, ANY=FALSE){
> if (super) classes<-unlist(sapply(classes, function(cl) getAllSuperClasses(getClass(cl))))
> if (ANY) classes<-c(classes,"ANY")
> gens<-allGenerics()@.Data
> sigs<-lapply(gens, function(g) linearizeMlist(getMethods(g))@classes)
> names(sigs)<-gens@.Data
> sigs<-lapply(sigs, function(gen){ gen[unlist(sapply(gen, function(sig) any(sig %in% classes)))]})
> sigs[sapply(sigs,length)>0]
> }
>
>
> Thomas Lumley Assoc. Professor, Biostatistics
> tlumley@u.washington.edu University of Washington, Seattle
>
> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.


R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Thu Jul 20 08:30:58 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Thu 20 Jul 2006 - 18:18:02 EST.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.