[Rd] Assignment of a derived instance to the parent container. S3/S4 differences

From: Wolski <wolski_at_molgen.mpg.de>
Date: Tue 21 Sep 2004 - 03:20:46 EST


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



R-devel@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Tue Sep 21 03:25:44 2004

This archive was generated by hypermail 2.1.8 : Wed 03 Nov 2004 - 22:45:16 EST