Dear colleagues,
there is a behaviour with S4 (virtual) classes that I find very hard to
understand: Depending on the position
of setAs(), the tree of inheritance changes.
This is my baseline example that defines the classes "grandma", "mother",
"daughter" and a virtual
class "mr_x". For a new instance if "daughter", "mr_x" is betweeen "mother" and
"grandma".
setClass("grandma", slots = c(a = "character"))
setClass("mother", slots = c(b = "matrix"), contains = "grandma")
setClass("daughter", slots = c(c = "list"), contains = "mother")
setClassUnion(name = "mr_x", members = c("daughter", "mother"))
setAs(from = "daughter", to = "grandma", def = function(from) new("grandma"))
is(new("daughter"))
[1] "daughter" "mother" "mr_x" "grandma"
Yet if I change the order of setAs() and setClassUnion(), this alters the
pattern of inheritance.
setClass("grandma", slots = c(a = "character"))
setClass("mother", slots = c(b = "matrix"), contains = "grandma")
setClass("daughter", slots = c(c = "list"), contains = "mother")
setAs(from = "daughter", to = "grandma", def = function(from) new("grandma"))
setClassUnion(name = "mr_x", members = c("daughter", "mother"))
is(new("daughter"))
[1] "daughter" "mother" "grandma" "mr_x"
Is there a reasonable explanation for this behavior? I could not find any and I
would appreciate
your help. If it is not an unintended behavior, I find it very confusing and
hard to anticipate.
Kind regads
Andreas
--
Prof. Dr. Andreas Blätte
Professor of Public Policy and Regional Politics
University of Duisburg-Essen
[[alternative HTML version deleted]]
______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel