[R] setAs vs setIs

From: Christophe Genolini <cgenolin_at_u-paris10.fr>
Date: Mon, 17 Mar 2008 01:12:51 +0100

Hi the list

I am fighting with the twins setAs and setIs...

Here are some questions and comments (comments to myself but that migth be wrong, it is why I am posting them)
1. Very surprising : using setIs define 'is', 'as<-' but not 'as' ??? 2. Using setAs define 'as', 'as<-' but not 'is'... What surprise me is that as<- can be define by both. I would have thing that setis is for 'is', setAs is for 'as' and 'as<-'... Since it is not the case, is there a possibility to set with only one function 'as', 'is' and 'as<-'

Last point, I get a warning using setAs. I did not manage to find the name of the variable it want me to use...

### Data

b <- new("B",b=3)
c <- new("C",c=4)
d <- new("D",d=5)

### using setIs


    test=function(object){return(object_at_c>0)},     replace=function(from,values){

        from_at_c <- values_at_b^3


is(c,"B")             #Ok
as(c,"B")             #not ok
as(c,"B") <- b        #ok (!)

### using setAs


    function(from,to){to<-new("B",b=from_at_d);return(to)},     replace=function(from,values){


is(d,"B")             # not ok
as(d,"B")             # ok
as(d,"B")<-b          # ok



R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Mon 17 Mar 2008 - 00:21:54 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 17 Mar 2008 - 01:30:22 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive