Wolski
2004-Sep-20 19:20 UTC
[Rd] Assignment of a derived instance to the parent container. S3/S4 differences
Hi, Is it intended to support assignment of a derived instance (S3) to a parent container (S4)? setClass("any") setClass("myclass",representation(x="any",y="any")) # I define parent containers x,y #I have an S3 object. xx<-3 class(x) #instantiate a new object of class myclass tt<-new("myclass") tt@x<-xx #not allowed as expected. # I want to assign xx anyway. This should be possible if xx inherits class "any". This can be easily achieved by ?class. class(xx)<-c(class(xx),"any") class(xx) #now it is of class "any" tt@x <- xx #but it still can not be assigned to the parent container. #The same works for 'pure' S4 classes. setClass("Numeric",contains="any") xx<-new("Numeric") is(xx) tt@x<-xx #works. Is it intended to support S3 class inheritance within S4? It would be great because most of the objects in R are still S3. Yours /E