From wolski at molgen.mpg.de  Fri Oct  8 10:24:07 2004
From: wolski at molgen.mpg.de (Witold Eryk Wolski)
Date: Fri Oct  8 10:24:17 2004
Subject: [Rd] Function _coerce_ in _setIs_ never entered (S4).
Message-ID: <41664EA7.60007@molgen.mpg.de>

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


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