[R] usage and behavior of 'setIs'

Matthias.Kohl@uni-bayreuth.de Matthias.Kohl at uni-bayreuth.de
Mon Oct 25 12:34:42 CEST 2004


Thank you,

Matthias

> 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:
>
> https://stat.ethz.ch/pipermail/r-devel/2004-October/030980.html
>
> 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.
>
> /E
>
>
> Matthias.Kohl at uni-bayreuth.de wrote:
>
>>Hello,
>>
>>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,
>>Matthias
>>
>>
>># 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
>>    })
>>
>>getClass("List1")
>># states explicit coerce for 'list' and 'vector'
>>getClass("List2")
>>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
>>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
>
> ______________________________________________
> 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




More information about the R-help mailing list