From hp@ge@ @end|ng |rom |redhutch@org  Tue Aug 20 01:23:25 2019
From: hp@ge@ @end|ng |rom |redhutch@org (Pages, Herve)
Date: Mon, 19 Aug 2019 23:23:25 +0000
Subject: [Rd] class() bug when used within a validity method
Message-ID: <8415ec8f-bbfe-3be2-72f0-4c2472f7575f@fredhutch.org>

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


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