[Rd] Function _coerce_ in _setIs_ never entered (S4).

From: Witold Eryk Wolski <wolski_at_molgen.mpg.de>
Date: Fri 08 Oct 2004 - 18:24:07 EST


Hi,

Please consider the following trivial example. In the sample code I first define a class MVCa using composition. This class contains a slot of type list.
Next I define an inheritance relation using the function setIs -> MVCa "is a" list.
Then I define a function printlength which prints the list-length which is defined for the type "list".
If I call this function assigning to their argument an object of class MVCa I would expect that the function _coerce_ defined in setIs will be called.
It seems that this never happens using:
R : Copyright 2004, The R Foundation for Statistical Computing Version 2.0.0 Patched (2004-10-04), ISBN 3-900051-07-0

setClass(

         "MVCa"

,representation(list="list"
,content="character")
,prototype(content="numeric")
)

setIs("MVCa","list",coerce=function(obj){obj@list},replace=function(obj,value){obj@list<-value})

setGeneric("printlength",function(object,...) standardGeneric("printlength"))
setMethod("printlength"

          ,signature(object="list")
          ,def=function(object)
          {
            print(length(object))
          }
          )


xx<-as.list(1:4)
names(xx)<-letters[1:4]
mvca<-new("MVCa")
mvca@list<-xx

printlength(mvca)

Any suggestions?

/E

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

______________________________________________
R-devel@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Received on Fri Oct 08 18:36:14 2004

This archive was generated by hypermail 2.1.8 : Fri 18 Mar 2005 - 09:00:30 EST