From mdowle at mdowle.plus.com  Thu Jul 12 18:54:39 2012
From: mdowle at mdowle.plus.com (Matthew Dowle)
Date: Thu, 12 Jul 2012 16:54:39 +0000
Subject: [Rd] Understanding tracemem
References: <CABdHhvFfhO-FCa94FE7Tm1qrd1fp7y72Zq-rHN8_84rDig@mail.gmail.com>
Message-ID: <loom.20120712T185107-931@post.gmane.org>

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



[Rd] Understanding tracemem
Matthew Dowle