Re: [Rd] sort.int(S3object) strips class but not the is.object flag

From: William Dunlap <wdunlap_at_tibco.com>
Date: Mon, 11 Apr 2011 10:28:22 -0700

> -----Original Message-----
> From: r-devel-bounces_at_r-project.org
> [mailto:r-devel-bounces@r-project.org] On Behalf Of William Dunlap
> Sent: Monday, April 11, 2011 10:10 AM
> To: R-devel_at_r-project.org
> Subject: [Rd] sort.int(S3object) strips class but not the
> is.object flag
>
> If x has an S3 class then sort.int(x) returns a value
> without an S3 class but which has the is.object flag set,
> which, I think, causes identical() give a false/misleading
> report:
>
> > x <- structure(1:3, class="unrecognizedClass")
> > y <- sort.int(x)
> > t <- 1:3
> > identical(y, t) # expect TRUE
> [1] FALSE
The misleading is.object flag can also affect the time it takes to sort objects (it looks like xtfrm is only called when is.object reports TRUE):   > system.time(for(i in 1:1e5) order(y)) # is.object(y) is TRUE

     user system elapsed
    12.07 0.00 11.28
  > system.time(for(i in 1:1e5) order(t)) # is.object(t) is FALSE

     user  system elapsed 
     1.98    0.01    2.01

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com  

> > identical(as.vector(y), as.vector(t)) # expect TRUE
> [1] FALSE
> > dput(y)
> 1:3
> > dput(t)
> 1:3
> > class(y)
> [1] "integer"
> > class(t)
> [1] "integer"
> > is.object(y)
> [1] TRUE
> > is.object(t)
> [1] FALSE
>
> The files made by
> save(t, file="t.Rdata", compress=FALSE)
> save(y, file="y.Rdata", compress=FALSE)
> differ in 2 places, where the first is presumably
> the name of the object:
> % cmp -l y.Rdata t.Rdata
> 36 171 164
> 39 1 0
> (The problem persists after a save/load cycle.)
>
> This is on R 2.12.2 on Linux. Sorry, I don't have 2.13.0
> yet installed.
>
> Bill Dunlap
> Spotfire, TIBCO Software
> wdunlap tibco.com
>
> ______________________________________________
> R-devel_at_r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>



R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Mon 11 Apr 2011 - 17:31:59 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 11 Apr 2011 - 18:40:43 GMT.

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

list of date sections of archive