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

Witold Eryk Wolski wolski at molgen.mpg.de
Fri Jan 7 14:46:49 CET 2005


Giles Heywood wrote:

>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?"]
>
>  
>
Hi,

 > setClass("foo",representation("matrix"))
[1] "foo"
 > a <- new("foo",array(NA,2:4))
 > b <- new("foo",matrix(NA,2,3))
 >
Will work.
As you say array has a subclass matrix.

getClass("array")
....
Known Subclasses: "matrix"

and

getClass("matrix")
Known Subclasses:
Class "array", directly, with explicit test and coerce

and matrix has a subclass array.

What probably is necessary to use polymorphism -> assigning a subclass 
to the parent class is the "explicit test and coearce".
It seems that matrix is the superclass of array.

/E

>______________________________________________
>R-help at stat.math.ethz.ch mailing list
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>
>  
>




-- 
Dipl. bio-chem. Witold Eryk Wolski
MPI-Moleculare Genetic
Ihnestrasse 63-73 14195 Berlin
tel: 0049-30-83875219                 __("<    _
http://www.molgen.mpg.de/~wolski      \__/    'v'
http://r4proteomics.sourceforge.net    ||    /   \
mail: witek96 at users.sourceforge.net    ^^     m m
      wolski at molgen.mpg.de




More information about the R-help mailing list