I'm using setMethodS3
in package R.methodsS3 to create an S3 method. Lets say I have two classes, class Parent
and class Child
(R.oo object). class Child
inherits from class Parent
. Both have the method MyMethod()
. How do I call superclass MyMethod()
(Parent's MyMethod
) from Child's MyMethod()
? I tried this$MyMethod(), but it calls Child's MyMethod()
Here's a reduced example:
library( R.oo )
setConstructorS3( "Parent" , definition =
function()
{
extend( Object() , "Parent" , .stateVar1 = FALSE )
} )
setMethodS3( "MyMethod" , "Parent" , appendVarArgs = FALSE , definition =
function( this , someParam , ... )
{
print( this$.stateVar1 )
print( someParam )
} )
setConstructorS3( "Child" , definition =
function()
{
extend( Parent() , "Child" )
} )
setMethodS3( "MyMethod" , "Child" , appendVarArgs = FALSE , definition =
function( this , someParam , ... )
{
NextMethod( "MyMethod" ) # does not work
this$MyMethod( someParam ) # also does not work
} )
child = Child()
child$MyMethod()