From hadley at rice.edu  Thu Jul 12 19:20:56 2012
From: hadley at rice.edu (Hadley Wickham)
Date: Thu, 12 Jul 2012 10:20:56 -0700
Subject: [Rd] Understanding tracemem
In-Reply-To: <4FFF02F4.4050400@stats.ox.ac.uk>
References: <CABdHhvFfhO-FCa94FE7Tm1qrd1fp7y72Zq-rHN8_84rDig__NQ@mail.gmail.com>
	<4FFF02F4.4050400@stats.ox.ac.uk>
Message-ID: <CABdHhvHDxJWD3OLyYb2HLQPKSbVrA=gg0hk50SMksBVMVgwLdA@mail.gmail.com>

> Read the help carefully as to what 'copy' means:
>
>      When an object is traced any copying of the object by the C
>      function ?duplicate? produces a message to standard output, as
>      does type coercion and copying when passing arguments to ?.C? or
>      ?.Fortran?.
>
> If you want to understand when 'duplicate' is called, you need to read the
> source code.  File src/main/subassign.c will explain the different paths
> taken by your two cases.  But isn't it rather obvious that duplicating x is
> not useful when a new longer vector needs to be created?

Thanks, that's useful.

Is there any way to detect when a new longer vector is created?  i.e.
I know that this creates a new vector:

x <- 1:10
x[11] <- 11L

And this doesn't

y <- list2env(as.list(x))
y$a <- 11

But does this?

z <- as.list(x)
z$a <- 11

And thanks to the off-list commenters who pointed out that x[5] <- 5
is duplicated because 5 is numeric, not integer (oops!)

Hadley

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



[Rd] Understanding tracemem
Hadley Wickham