[R] S4 base class

Duncan Murdoch murdoch.duncan at gmail.com
Thu Oct 17 15:19:30 CEST 2013


On 17/10/2013 9:01 AM, Michael Meyer wrote:
> Sorry,
>
> if the previous message seems without context.
> Indeed, the first message was bounced by filtering rules (triggered by subject heading than which nothing could be more benign or less liable to suspician). It was:
>
> Greetings,
>
> I have an S4 class "B" (Base) which defines a function f=f(this="B",...)
> Dervided from B we have a derived class D which also defines a function f=f(this="D",...)
>
> In the definition of D::f we want to call the version B::f and could do this by simply calling
>
> f(baseClassObject(this),...)
>
> The question is the following:
>
> How do I refer to the base class object from the derived class?

You're asking the wrong question.  You should be asking how to call the 
method for the inherited class .  callNextMethod() is the answer to that 
question.

By the way, your use of the syntax D::f and B::f suggests that you're 
thinking from a C++ point of view.  That's very likely to lead to 
frustration:  the S4 object system is very different from C++.  Methods 
don't belong to classes, they belong to generics. There is no such thing 
as D::f or B::f, only f methods with different signatures.

Duncan Murdoch



More information about the R-help mailing list