[R] Re: S4 method inheritance
Ross Boylan
ross at biostat.ucsf.edu
Tue May 24 21:30:11 CEST 2005
On Tue, May 24, 2005 at 07:07:07AM -0400, Duncan Murdoch wrote:
> Ross Boylan wrote:
> >On Mon, 2005-05-23 at 14:41 -0700, Ross Boylan wrote:
> >....
> >
> >
> >>Finally, I'm a bit concerned that one article mentioned that S4
> >>inheritance, in practice, is used mostly for data, not methods (Thomas
> >>Lumley, R News 4(1), June 2004: p. 36). Am I going down a road I
> >>shouldn't travel?
> >>
> >
> >Hmm, maybe I just found out. If B is an S4 subclass of A (aka extends
> >A), how does B's method foo invoke A's foo?
>
> Your question doesn't make sense in S4. In S4, classes don't have
> methods, generics have methods. There's no such thing as "B's method"
> or "A's method".
Oops, I keep taking the references to "objects" too literally. Thanks.
>
> You might get what you want with foo(as(bObject, "A")) if bObject is an
> instance of class B.
>
> >The question assumes that A's foo was defined as an in place function,
> >so there's no (obvious) named object for it, i.e,
> >setMethod("A", signature(blah="numeric"), function(x) something)
There's my confusion: the first argument should be the name of the
generic, not the class.
>
> I don't know what you mean by "in place function", but I hope my answer
> helps anyway.
Just for clarification, "in place function" was in contrast to a
function defined elsewhere with an explicit name, e.g.,
fforA<-function(x) something
setMethod("foo", signature(blah="numeric"), fforA)
In that case I could just refer to fforA directly. (Trying to avoid
the S3ish f.A).
Is sounds as if the use of as() or callNextMethod() will get me what I
want. And the docs seem clear that callNextMethod() returns control
(and a value) to the calling function.
Thanks to everyone for their help.
More information about the R-help
mailing list