[Rd] S4 inheritance and old class
julien_ide
julien.ide.fr at gmail.com
Thu May 28 15:23:12 CEST 2015
Hey everyone,
I would like to develop a package using S4 classes.
I have to define several S4 classes that inherits from each others as
follow:
# A <- B <- C <- D
I also would like to define .DollarNames methods for these classes so, if I
have understood well, I also have to define an old class as follow:
# AOld <- A <- B <- C <- D
setOldClass(Classes = "AOld")
setClass(
Class = "A",
contains = "AOld",
slots = list(A = "character")
)
.DollarNames.A <- function(x, pattern)
grep(pattern, slotNames(x), value = TRUE)
setClass(
Class = "B",
contains = "A",
slots = list(B = "character"),
validity = function(object){
cat("Testing an object of class '", class(object),
"'' with valitity function of class 'B'", sep = "")
cat("Validity test for class 'B': ", object at A, sep = "")
return(TRUE)
}
)
setClass(
Class = "C",
contains = c("B"),
slots = list(C = "character"),
validity = function(object){
cat("Testing an object of class '", class(object),
"'' with valitity function of class 'C'", sep = "")
cat("Validity test for class 'C': ", object at A, sep = "")
return(TRUE)
}
)
setClass(
Class = "D",
contains = "C",
slots = list(D = "character"),
validity = function(object){
cat("Testing an object of class '", class(object),
"'' with valitity function of class 'D'", sep = "")
cat("Validity test for class 'D': ", object at A, sep = "")
return(TRUE)
}
)
My problem is that when I try to create an object of class "D" and test its
validity
validObject(new("D"))
it seems that at some point the object is coerced to an object of class
"AOld" and tested by the validity function of class "B".
Of course it returns an error. What am I missing here?
Julien
--
View this message in context: http://r.789695.n4.nabble.com/S4-inheritance-and-old-class-tp4707840.html
Sent from the R devel mailing list archive at Nabble.com.
More information about the R-devel
mailing list