[R] setAs vs setIs

Christophe Genolini cgenolin at u-paris10.fr
Mon Mar 17 09:42:09 CET 2008


I works, great !
So using your code, we can define 'as','as<-' and 'is' with setIt. Is 
there still any interest using setAs ?

Christophe
>
> It seems to me your problem here is simply that you did not define a 
> coerce cal in setIs, so it does not know how to turn a C object into a 
> B object, which is what you ask it to do here. It knows how to test if 
> C object is also a B object, because of the test function you 
> provided, and it can do the replacement you ask it in as(c,"B") <-b 
> because of the replace command you provided, but the third part is 
> missing. Perhaps something like this:
> setIs("C","B",
>     test=function(object){return(object at c>0)},
>     replace=function(from,values){
>         from at c <- values at b^3
>         return(from)
>     },
>     coerce=function(from) {
>         new("B",b=from at c^(1/3))
>     }
> )



More information about the R-help mailing list