[Rd] class() bug when used within a validity method

Pages, Herve hp@ge@ @end|ng |rom |redhutch@org
Tue Aug 20 01:23:25 CEST 2019


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 using fredhutch.org
Phone:  (206) 667-5791
Fax:    (206) 667-1319


More information about the R-devel mailing list