[R] usage and behavior of 'setIs'

Witold Eryk Wolski wolski at molgen.mpg.de
Mon Oct 25 12:02:02 CEST 2004

Hi Matthias,

A similar problem to yours (with one level of inheritance less) was 
disccussed this month on the r-devel list.
You find an answer from JChambers here:


And yes specifying _setAs_  to each _setIs_ with the coerce and replace 
is a _hack_ which is with this version of methods necessary when 
inherting from Old Classes.


Matthias.Kohl at uni-bayreuth.de wrote:

>am I using 'setIs' in the correct way in the subsequent (artifical) example?
>Do I have to specify explicit 'setAs' for 'list' and 'vector' or
>should this work automatically, since "getClass("List1")" states
>an explicit coerce also for these classes.
>I'm working with R 2.0.0 Patched (2004-10-06) on windows 2000.
>Thanks for your advice,
># example
>setClass(Class = "List1", representation(List = "list"))
>setClass(Class = "List2", contains = "list")
>setIs(class1 = "List1", class2 = "List2",
>    coerce = function(obj){ new("List2", obj at List) },
>    replace = function(obj, value){
>        obj at List <- value
>    })
># states explicit coerce for 'list' and 'vector'
>L1 <- new("List1", List = list("a"))
># all TRUE
>is(L1, "List2")
>is(L1, "list")
>is(L1, "vector")
>as(L1, "List2") # works
># both return 'list()'
># why not a 'list' with entry "a"?
># Is there an additional 'setAs' needed?
>as(L1, "list")
>as(L1, "vector")
>L2 <- as(L1, "List2")
>as(L2, "list") # works
>as(L2, "vector") # works
>R-help at stat.math.ethz.ch mailing list
>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