Hi,
I would like to create some S4 classes as follows

setClass("Father",representation(name="character"))
setClass("Son1",contains="Father",representation(par="numeric"))
setClass("Son2",contains="Father",representation(par="logical"))

Son1<-new("Son1")
Son1@name<-"Son1"
Son1@par<-3

Son2<-new("Son2")
Son2@name<-"Son2"
Son2@par<-TRUE

setGeneric("get.par",function(object){standardGeneric ("get.par")})
setMethod("get.par","Son1",function(object){return(object@par+3)})
setMethod("get.par","Son2",function(object){return(!object@par)})

get.par(Son1)
get.par(Son2)

So far, so good. I would like now, to create a new class, which
"extends"/"contains" the subclasses of Father by some additional slots.
Is there any clean and simple possibility to inherite also the corresponding
function get.par ?

setClass("Extension",representation(person="Father",text="character"))
Ext<-new("Extension")
Ext@text<-"new try"
Ext@person<-Son1
get.par(Ext)
get.par(Ext@person)

Of course, "get.par(Ext)" returns an error. Is there any possibility to tell
R, that if now function exists for a Class, to transform the object to a
class, for which the function exists ? (I know, it is not very clear what I
am writing, but I am doing my best). I don't want to rewrite every method
for  "Extension" like

setMethod("get.par","Extension",function(object){get.par(object@person)})

Is there any simpler solution by steClassUnion, setAs, setIs .... ?

Thanks a lot in advance

Alexander

--
View this message in context: 
http://r.789695.n4.nabble.com/Extending-a-group-of-S4-classes-by-setClassUnion-tp4475251p4475251.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to