[R] Methods dispatch and inheritance R.oo

Yuri Volchik yuri.volchik at gmail.com
Wed Nov 5 11:18:17 CET 2008


Hi to all members, i have a question about class inheritance and methods
using R.oo package:
I have the following code and it doesn't work, guess i'm doing smth wrong
and there is nothing in the help. 

library(R.oo)

setConstructorS3("ClassA", function(A=15) {
  extend(Object(), "ClassA", 
    .size = A
  );
})


setMethodS3("print", "ClassA", function(this,...) {
  print(paste('Class A:',this$.size));
})


objA<-ClassA();
objA

[1] "Class A: 15"

setConstructorS3("ClassB", function(B=15) {
  extend("ClassA", "ClassB", 
    .size2 = B
  );
})


setMethodS3("print", "ClassB", function(this,...) {
  print(paste('Class B:',this$.size2));
})


objB<-ClassB();
objB

Error in this$.size2 : $ operator is invalid for atomic vectors


-- 
View this message in context: http://www.nabble.com/Methods-dispatch-and-inheritance-R.oo-tp20339090p20339090.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list