[R] S4 class no longer accepts matrix in array slot under 2.0.1

Giles Heywood giles.heywood at btinternet.com
Fri Jan 7 13:28:22 CET 2005


I have an S4 class with a slot of class "array", and in upgrading to 2.0.1
(from 1.9.1) I have encountered a change in behaviour. This causes me some
difficulties if I want to allow 2-dimensional arrays in the slot.

The following (in 2.0.1) illustrates the point:

> setClass("foo",representation("array"))
[1] "foo"
> a <- new("foo",array(NA,2:4))
> b <- new("foo",matrix(NA,2,3))
Error in "as<-"(`*tmp*`, Classi, value = c(NA, NA, NA, NA, NA, NA)) :
        No method or default for as() replacement of "foo" with
Class="matrix"

This last error did not occur under 1.9.1.

I conclude that in this context the methods package does not recognise
"matrix" as a subclass of "array". However if I use getClass(), I see that R
recognises "matrix" as a subclass of "array" (and vice-versa).  So is this
new behaviour correct?

[this is a simplified (and final) reposting of an earlier question entitled
"matrix no longer "is" array in 2.0.1?"]




More information about the R-help mailing list