Re: [R] How to find S4 generics?

From: Prof Brian Ripley <ripley_at_stats.ox.ac.uk>
Date: Thu 20 Jul 2006 - 04:41:24 EST

On Wed, 19 Jul 2006, Spencer Graves wrote:

> Dear Prof. Ripley:
>
> Thanks very much.
>
> 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)?

It is correct that in principle there could be such a function in the methods package, but not that methods() in utils could be revised to do so. (For efficiency reasons on the stats4 package in the base distribution may depend on methods)

> I ask, because it's not always obvious (at least to me) what helper
> functions are available. Some but not all are mentioned in the documentation,
> and even if they are, they may not be featured prominently. For the S3
> standard, methods(class=...) reports what's available, and it's faster and
> more reliable than scanning the help files. After I find something with
> methods(class=...), then I have better ideas for what to look for in the
> documentation.
>
> Best Wishes,
> Spencer Graves
>
> Prof Brian Ripley wrote:
> > On Tue, 18 Jul 2006, Spencer Graves wrote:
> >
> > > *****
> > > ***** "methods" *****
> > > *****
> > > You have asked an excellent question. I can provide a partial
> > > answer below. First, however, I wish to pose a question of my own, which
> > > could help answer your question:
> > >
> > > How can one obtain a simple list of the available generics for a
> > > class? For an S3 class, the 'methods' functions provide that. What about
> > > an S4 class? That's entirely opaque to me, if I somehow can't find the
> > > relevant information in other ways. For example, ?lmer-class lists many
> > > but not all of the methods available for objects of class 'lmer'. I think
> > > I once found a way to get that, but I'm not able to find documentation on
> > > it now.
> >
> > It doesn't work the same way. S3 generics are defined on a single argument
> > and hence have methods for a class, and so it is relevant to ask what
> > generics there are which have methods for a given class - but even then
> > there can be other generics and other methods which dispatch on object from
> > that class by inheritance (e.g. on "lm" for "glm" objects).
> >
> > S4 generics dispatch on a signature which can involve two or more classes,
> > and I guess the simplest interpretation of your question is
> >
> > `what S4 generics are there which have methods with signatures mentioning
> > this class'.
> >
> > Given the decentralized way such information is stored, I think the only way
> > to do that is to find all the generics currently available (via getGenerics
> > or its synonym allGenerics) and then call showMethods on each generic. In
> > particular, methods are stored in the S4 generic and not in the package
> > defining the method.
> >
> > However, I suspect inheritance is much more important here, and there is no
> > way to know if methods for class "ANY" actually work for a specific S4
> > class.
> >
> > [...]
> >
>
>
>
>

-- 
Brian D. Ripley,                  ripley@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

______________________________________________
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 05:58:48 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 - 06:16:27 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.