Sirs:

My validity function did not run when my class contains="matrix". But if I
first define the class with contains="numeric", then define it again
with contains="matrix", validity runs. Here's the session:

> f <- function(object) "BAD CLASS" # force error to
> setClass("A", contains="matrix", validity=f)
[1] "A"
> new("A",as.matrix(1)) # should generate a validity error, does not
An object of class “A”
     [,1]
[1,]    1
> setClass("B", contains="numeric", validity=f)
[1] "B"
> new("B",1) # generates the error
Error in validObject(.Object) : invalid class "B" object: BAD CLASS
> setClass("B", contains="matrix", validity=f)
[1] "B"
> new("B",as.matrix(1)) # generates the error
Error in validObject(.Object) : invalid class "B" object: BAD CLASS

On the other hand, when I define the class with "matrix" in its
representation, validity is called, no work-around necessary:

> setClass("C", representation(a="matrix"), validity=f)
[1] "C"
> new("C",a=as.matrix(1)) # error, as desired
Error in validObject(.Object) : invalid class "C" object: BAD CLASS

Should I
1) always put "matrix" into the setClass representation argument instead of
the contains argument, or
2) use contains="numeric", put the matrix's dims and dimnames attributes
into slots, and rely on a constructor to populate the instance?

Option 2 seems most "stable".

Thanks,
Dan Murphy

Windows Vista, R version 2.11.0 (2010-04-22)

        [[alternative HTML version deleted]]

______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel

Reply via email to