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

Wolski wolski at molgen.mpg.de
Mon Sep 20 19:20:46 CEST 2004


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 at 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 at 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 at 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



More information about the R-devel mailing list