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

Witold Eryk Wolski wolski at molgen.mpg.de
Fri Oct 8 10:24:07 CEST 2004


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 at list},replace=function(obj,value){obj at 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 at 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 at users.sourceforge.net    ^^     w w
      wolski at molgen.mpg.de



More information about the R-devel mailing list