[R] Is there lazy copy in R?

tlumley at u.washington.edu tlumley at u.washington.edu
Tue Dec 15 19:11:36 CET 2009


On Wed, 16 Dec 2009, Peng Yu wrote:

> On Tue, Dec 15, 2009 at 10:32 PM, hadley wickham <h.wickham at gmail.com> wrote:
>>> I don't understand what these addresses mean. Would you please help me
>>> understand it?
>>
>> Did you try reading the documentation?
>>
>>     When an object is traced any copying of the object by the C
>>     function ‘duplicate’ or by arithmetic or mathematical operations
>>     produces a message to standard output.  The message consists of
>>     the string ‘tracemem’, the identifying strings for the object
>>     being copied and the new object being created, and a stack trace
>>     showing where the duplication occurred.  ‘retracemem()’ is used to
>>     indicate that a variable should be considered a copy of a previous
>>     variable (e.g. after subscripting).
>
> "The message consists of the string ‘tracemem’, the identifying
> strings for the object being copied and the new object being created,
> and a stack trace showing where the duplication occurred."
>
> I tried to read the document before I posted, but wasn't be able to
> understand it, because there are multiple ways to parse it.
>
> To make sure that I understand, I rewrite the above sentence to the
> following. Is it correct?
>
> "The message consists of the string ‘tracemem’, the string indicating
> the object being copied,  the string indicating the new object being
> created, and a stack trace showing where the duplication occurred."
>
> I also didn't see a stack trace in my example. If I didn't see Martin
> Morgan's post, I will still be confused.
>

The stack trace is there, it's just that it is empty because you aren't in a function.

> I thought that there should be only one coping. Why there are two lines?
>
> tracemem[0x05cf2798 -> 0x05cf2750]:
> tracemem[0x05cf2750 -> 0x05ed8ba0]:
>

There are two lines because there are two copies.  One is the lazy copy because the object is modified, the other is because it is converted from integer to numeric.

The whole point of tracemem() is to show copies that you didn't expect, so being surprised by it is a good thing.

      -thomas

Thomas Lumley			Assoc. Professor, Biostatistics
tlumley at u.washington.edu	University of Washington, Seattle


More information about the R-help mailing list