[R] showMethods()! Re: How to find S4 generics?
Spencer Graves
spencer.graves at pdf.com
Thu Jul 20 16:43:14 CEST 2006
Hi, Martin:
I looked for 'showMethods' before I posted this question. I see two
possible reasons others might not have mentioned it previously -- and
why my post didn't mention it:
HARD TO FIND
Now that you have mentioned it, I recall having stumbled across it
and used it once before. It would help mightily if other relevant help
pages included 'showMethods' under 'See Also', including 'methods'.
Looking just now, I found it there under 'GenericFunctions'. However,
before I raised this question to the list, I spent maybe 20-30 minutes
looking for it in different help pages, using RSiteSearch, etc., without
success.
NOT AS USEFUL AS THE NAME IMPLIES
Just now I tried '> showMethods(classes="lm")' and (with 'lme4' in
the path' showMethods(classes="lmer"). With the results below. I
didn't find 'coef' or 'predict' or ... .
Thanks for the suggestion.
Spencer Graves
###################
> sessionInfo()
Version 2.3.1 (2006-06-01)
i386-pc-mingw32
attached base packages:
[1] "methods" "stats" "graphics" "grDevices" "utils" "datasets"
[7] "base"
other attached packages:
lme4 Matrix lattice robustLog
"0.995-2" "0.995-11" "0.13-9" "0.0-2"
> showMethods(classes="lm")
Function "addNextMethod":
<Empty Methods List>
Function "Arith":
<Empty Methods List>
Function "body<-":
<Empty Methods List>
Function "cbind2":
<Empty Methods List>
Function "coerce":
<Empty Methods List>
Function "Compare":
<Empty Methods List>
Function "initialize":
<Empty Methods List>
Function "loadMethod":
<Empty Methods List>
Function "Math":
<Empty Methods List>
Function "Math2":
<Empty Methods List>
Function "rbind2":
<Empty Methods List>
Function "show":
<Empty Methods List>
Function "Summary":
<Empty Methods List>
NULL
> showMethods(classes="lmer")
Function "addNextMethod":
<Empty Methods List>
Function "Arith":
<Empty Methods List>
Function "body<-":
<Empty Methods List>
Function "cbind2":
<Empty Methods List>
Function "coerce":
<Empty Methods List>
Function "Compare":
<Empty Methods List>
Function "initialize":
<Empty Methods List>
Function "loadMethod":
<Empty Methods List>
Function "Math":
<Empty Methods List>
Function "Math2":
<Empty Methods List>
Function "rbind2":
<Empty Methods List>
Function "show":
<Empty Methods List>
Function "Summary":
<Empty Methods List>
NULL
Martin Maechler wrote:
>>>>>> "SpG" == Spencer Graves <spencer.graves at pdf.com>
>>>>>> on Wed, 19 Jul 2006 15:23:58 -0700 writes:
>
> SpG> Hi, Thomas: Thanks very much. I haven't tried it yet,
> SpG> but it looks very useful. Best Wishes, Spencer Graves
>
> Hmm, ?methods has been containing for a while
>
> methods> Note:
> methods>
> methods> This scheme is called _S3_ (S version 3). For new projects, it is
> methods> recommended to use the more flexible and robust _S4_ scheme
> methods> provided in the 'methods' package. Functions can have both S3 and
> methods> S4 methods, and function 'showMethods' will list the S4 methods
> methods> (possibly none).
>
> So I wonder why nowbody mentioned the official
>
> showMethods()
>
> (or are you all not reading the help pages ;-\) )
>
> It does not always return / print what I want exactly, and in
> the past, at one point I put some effort to make its output more
> customizable.
> I didn't put that effort to the end (*)
> but for the present case
>
> showMethods(class = "ddiMatrix", where = "package:Matrix")
>
> at least is pretty useful.
>
> (*) I think I had added the 'showEmpty = TRUE' argument
> where the current documentation says
>
> showM> showEmpty: logical indicating if methods with empty
> showM> method lists should be shown at all.
> showM> Note that 'FALSE' is _not yet implemented_.
>
> and the non-implementation had a reason: implementation was
> definitely much less simple than I had hoped ...
>
> Martin
>
>
> SpG> 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 at .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 at u.washington.edu University of Washington,
> >> Seattle
> >>
> >> ______________________________________________
> >> R-help at 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.
>
> SpG> ______________________________________________
> SpG> R-help at stat.math.ethz.ch mailing list
> SpG> https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do
> SpG> read the posting guide
> SpG> http://www.R-project.org/posting-guide.html and provide
> SpG> commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list