[R] setValidity() changes "Extends"?

Matthias Kohl Matthias.Kohl at uni-bayreuth.de
Fri Jun 11 11:30:52 CEST 2004


Hi,

I'm using Version 1.9.0  (2004-04-12)  on Windows NT/98/2000 and found 
the following difference between using setClass(..., valdity = ), 
respectively using setValidity() afterwards:

setValidity() changes the "Extends"-part of a derived class, is this 
intended or a bug or am I missing something?

##########################################
## Example code
##########################################
setClass("Class1", representation("name" = "character"))

if(!isGeneric("name")) setGeneric("name", function(object) 
standardGeneric("name"))
setMethod("name", "Class1", function(object) object at name)

setClass("Class2", representation("Class1"))
setClass("Class3", representation("Class2"))

getClass("Class3") # as I expected

#Slots:
#              
#Name:       name
#Class: character
#
#Extends:
#Class "Class2", directly
#Class "Class1", by class "Class2"


validClass3 <- function(object){TRUE}
setValidity("Class3", validClass3)

#Slots:
#             
#Name:       name
#Class: character
#
#Extends: "Class2"         # has been changed???

getClass("Class3")  # why does setValidity change "Extends"?
                              # am I missing something?
                              # This doesn't happen if I use
                              # setClass(..., validity = )
                              # It, of course, also works if I 
explicitly use
                              # setClass("Class3", contains = 
c("Class2", "Class1")

C32 <- new("Class3")
name(C32) # generates an error?!

#Error in name(C32) : No direct or inherited method for function "name" 
for this call

is(C32, "Class1") # however
#TRUE




More information about the R-help mailing list