Hi,
This is a long-standing bug where 'class(object)' does not
return the actual class of 'object' when used inside a validity
method. Instead it seems to return the class for which the validity
method is defined. For example:
setClass("A", slots=c(stuff="ANY"))
setValidity("A", function(object) {
cat("validating an object of class:", class(object),
"\n")
TRUE
})
Then:
a <- new("A")
validObject(a)
# validating an object of class: A
# [1] TRUE
which is OK. But trying to validate an object that belongs to a
subclass of A leads to a big surprise:
setClass("B", contains="A")
b <- new("B")
class(b)
# [1] "B"
validObject(b)
# validating an object of class: A
# [1] TRUE
The class of object 'b' as seen by class() is wrong.
Note that this doesn't happen if A is defined as a VIRTUAL class.
Cheers,
H.
--
Herv? Pag?s
Program in Computational Biology
Division of Public Health Sciences
Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N, M1-B514
P.O. Box 19024
Seattle, WA 98109-1024
E-mail: hpages at fredhutch.org
Phone: (206) 667-5791
Fax: (206) 667-1319
On 8/19/19 16:23, Pages, Herve wrote: ...> Note that this doesn't happen if A is defined as a VIRTUAL class.To be precise, when A is a VIRTUAL class, it requires at least one additional level of class extension to break class(): setClass("A", contains="VIRTUAL", slots=c(stuff="ANY")) setValidity("A", function(object) { cat("validating an object of class:", class(object), "\n") TRUE }) setClass("B", contains="A") setClass("C", contains="B") Then: c <- new("C") validObject(c) # validating an object of class: B # [1] TRUE H. -- Herv? Pag?s Program in Computational Biology Division of Public Health Sciences Fred Hutchinson Cancer Research Center 1100 Fairview Ave. N, M1-B514 P.O. Box 19024 Seattle, WA 98109-1024 E-mail: hpages at fredhutch.org Phone: (206) 667-5791 Fax: (206) 667-1319
Possibly Parallel Threads
- Pb with validObject(..., complete=TRUE)
- Unexpected failure when calling new() with unnamed arg and
- Was: setValidity and "initialize" method conflict ? [in R-help]
- Unexpected failure when calling new() with unnamed arg and
- Unexpected failure when calling new() with unnamed arg and