[Rd] classed
Thomas Lumley
thomas@biostat.washington.edu
Fri, 15 Sep 2000 10:33:33 -0700 (PDT)
On Fri, 15 Sep 2000, Paul Gilbert wrote:
>
> I've often wondered about this. Any comments from someone who really knows the
> internals of R? When I first implemented it I did some testing and didn't notice
> any really big slowdown and I do use a lot of fairly big (multi MB size)
> objects. But notice that the difference is really in the function call, not in
> the copying of objects. A function using classed would end
>
> classed(x, "whatever") }
>
> rather than
>
> class(x) <- "whatever"
> x}
>
> I think the copy is (or is not) made in both cases.
>
Setting an attribute doesn't result in a copy, but setting one in a
function will: a reference to x is initially passed to the function, but
when the attribute is set a copy is made so that the local x rather than
the global one is modified. I don't think another copy is made when
classed() returns, but I'm not sure. Using classed() makes at least one
more copy that using class()<-.
For interpreted "foo<-" functions this wouldn't be true -- the same
amount of copying would be done either way -- but class() is special.
-thomas
Thomas Lumley
Assistant Professor, Biostatistics
University of Washington, Seattle
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._