[Rd] Understanding tracemem

Matthew Dowle mdowle at mdowle.plus.com
Thu Jul 12 18:54:39 CEST 2012


Hadley Wickham <hadley <at> rice.edu> writes:

> Why does x[5] <- 5 create a copy

That assigns 5 not 5L. x is being coerced from integer to double.

x[5] <- 5L doesn't copy.

> , when x[11] (which should be
> extending a vector does not) ?  I can understand that maybe x[5] <- 5
> hasn't yet been optimised to not make a copy, but if that's the case
> then why doesn't x[11] <- 11 make one?

Extending a vector is creating a new (longer) vector and copying the old 
(shorter) one in.  That's different to duplicate().  tracemem only reports 
calls to duplicate().

Matthew



More information about the R-devel mailing list