[R] S4 : defining [<- using inheritance from 2 classes

cgenolin cgenolin at u-paris10.fr
Fri Nov 18 06:46:44 CET 2011


Hi the list,

I define a class 'C' that inherit from two classes 'A' and 'B'. 'A' and 'B'
have no slot with similar names.
----------------
setClass(
    Class="C",
    contains=c("A","B")
)


To define the get operator '[' for class "C", I simply use the get of "A" or
"B" (the constante 'SLOT_OF_A' is a character holding the names of all the
slot of A) :
----------------
setMethod("[","C",
  function(x,i,j,drop){
     if(i%in%SLOT_OF_A){
        x <- as(x,'A')
     }else{
        x <- as(x,'B')
     }
     return(x[i,j])
}
----------------

Is it possible to do something similar for the set operator '[<-' ?

Thanks
Christophe 

--
View this message in context: http://r.789695.n4.nabble.com/S4-defining-using-inheritance-from-2-classes-tp4082217p4082217.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list