[Rd] Understanding tracemem

Hadley Wickham hadley at rice.edu
Thu Jul 12 19:20:56 CEST 2012


> 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/



More information about the R-devel mailing list