From hadley at rice.edu  Thu Jul 12 18:15:06 2012
From: hadley at rice.edu (Hadley Wickham)
Date: Thu, 12 Jul 2012 09:15:06 -0700
Subject: [Rd] Understanding tracemem
Message-ID: <CABdHhvFfhO-FCa94FE7Tm1qrd1fp7y72Zq-rHN8_84rDig__NQ@mail.gmail.com>

Hi all,

I've been trying to get a better handle on what manipulations lead R
to duplicate a vector, creating small experiments and using tracemem
to observe what happens (all in 2.15.1). That's lead me to a few
questions, illustrated using the snippet below.

x <- 1:10
tracemem(x)
# [1] "<0x1058f8238>"
x[5] <- 5
# tracemem[0x1058f8238 -> 0x105994ab0]:
x[11] <- 11

Why does x[5] <- 5 create a 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? I thought it might be because
somehow tracemem loses track, but adding an additional tracemem(x)
after x[5] <- 5 doesn't change the output.

Hadley

-- 
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/



[Rd] Understanding tracemem
Hadley Wickham