Re: [R] Is there lazy copy in R?

2009-12-15 Thread Peng Yu
On Tue, Dec 15, 2009 at 10:32 PM, hadley wickham h.wick...@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.


I thought that there should be only one coping. Why there are two lines?

tracemem[0x05cf2798 - 0x05cf2750]:
tracemem[0x05cf2750 - 0x05ed8ba0]:

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Is there lazy copy in R?

2009-12-15 Thread tlumley

On Wed, 16 Dec 2009, Peng Yu wrote:


On Tue, Dec 15, 2009 at 10:32 PM, hadley wickham h.wick...@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
tlum...@u.washington.eduUniversity of Washington, Seattle
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Is there lazy copy in R?

2009-12-15 Thread Peng Yu
2009/12/15  tlum...@u.washington.edu:
 On Wed, 16 Dec 2009, Peng Yu wrote:

 On Tue, Dec 15, 2009 at 10:32 PM, hadley wickham h.wick...@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]:

I still don't understand what the numbers after 'tracemem[' are. Could
somebody please explain it?

 x=1:3
 tracemem(x)
[1] 0x1056ef8
 x[[4]]=8#I still don't understand what '0x9ac9f0' means here
tracemem[0x1056ef8 - 0x9ac9f0]:
 tracemem(x)#The address of 'x' is 0x9aca38 but not '0x9ac9f0'
[1] 0x9aca38



 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
 tlum...@u.washington.edu        University of Washington, Seattle


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Is there lazy copy in R?

2009-12-15 Thread tlumley

On Tue, 15 Dec 2009, Peng Yu wrote:


2009/12/15  tlum...@u.washington.edu:

On Wed, 16 Dec 2009, Peng Yu wrote:


On Tue, Dec 15, 2009 at 10:32 PM, hadley wickham h.wick...@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]:


I still don't understand what the numbers after 'tracemem[' are. Could
somebody please explain it?


They are the printed representations of the pointers to the objects on the R heap. In 
practice, they will be base-16 representations of  the memory addresses (though the C 
standard doesn't guarantee this).   The one before the - is the address of the 
object being copied; the one after the - is the address of the copy.   The point 
is to give names to each object, since they need not be R variables and may not have 
any other name.

In this trace you can see that the second copy is of the object created in the 
first copy.

   -thomas

Thomas Lumley   Assoc. Professor, Biostatistics
tlum...@u.washington.eduUniversity of Washington, Seattle
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Is there lazy copy in R?

2009-12-15 Thread Peng Yu
On Tue, Dec 15, 2009 at 2:34 PM, Peng Yu pengyu...@gmail.com wrote:
 2009/12/15  tlum...@u.washington.edu:
 On Wed, 16 Dec 2009, Peng Yu wrote:

 On Tue, Dec 15, 2009 at 10:32 PM, hadley wickham h.wick...@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]:

 I still don't understand what the numbers after 'tracemem[' are. Could
 somebody please explain it?

 x=1:3
 tracemem(x)
 [1] 0x1056ef8
 x[[4]]=8#I still don't understand what '0x9ac9f0' means here
 tracemem[0x1056ef8 - 0x9ac9f0]:
 tracemem(x)#The address of 'x' is 0x9aca38 but not '0x9ac9f0'
 [1] 0x9aca38

Hi Thomas,

The address of x after 'x[[4]]=8' is '0x9ac9f0'. Why the last
'tracement(x)' gives '0x9aca38'?


 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
 tlum...@u.washington.edu        University of Washington, Seattle



__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Is there lazy copy in R?

2009-12-14 Thread Peng Yu
I'm wondering if lazy copy is available in R or not. For example, in
the following code, I'm wondering if the memory for y is allocated in
the 2nd line or the 3rd line. Is there a documentation for this?

x=1:1
y=x
y[[10]]=5

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Is there lazy copy in R?

2009-12-14 Thread Benilton Carvalho
use tracemem() to figure out... and read its documentation in detail.
b


On Dec 15, 2009, at 1:03 AM, Peng Yu wrote:

 I'm wondering if lazy copy is available in R or not. For example, in
 the following code, I'm wondering if the memory for y is allocated in
 the 2nd line or the 3rd line. Is there a documentation for this?
 
 x=1:1
 y=x
 y[[10]]=5
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Is there lazy copy in R?

2009-12-14 Thread Peng Yu
 a=1:10
 b=a
 a=1:10
 tracemem(a)# I assume the following is address 'a' points to
[1] 0x05cf2798
 b=a
 b[1]=1
tracemem[0x05cf2798 - 0x05cf2750]:
tracemem[0x05cf2750 - 0x05ed8ba0]:

I don't understand what these addresses mean. Would you please help me
understand it?

On Mon, Dec 14, 2009 at 9:23 PM, Benilton Carvalho bcarv...@jhsph.edu wrote:
 use tracemem() to figure out... and read its documentation in detail.
 b


 On Dec 15, 2009, at 1:03 AM, Peng Yu wrote:

 I'm wondering if lazy copy is available in R or not. For example, in
 the following code, I'm wondering if the memory for y is allocated in
 the 2nd line or the 3rd line. Is there a documentation for this?

 x=1:1
 y=x
 y[[10]]=5

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.



__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Is there lazy copy in R?

2009-12-14 Thread hadley wickham
 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).

Hadley

-- 
http://had.co.nz/

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Is there lazy copy in R?

2009-12-14 Thread Linlin Yan
It means that R does have the lazy copy mechanism, which I didn't
know, and I think it can be very useful to make R running more
quickly.

On Tue, Dec 15, 2009 at 12:15 PM, Peng Yu pengyu...@gmail.com wrote:
 a=1:10
 b=a
 a=1:10
 tracemem(a)# I assume the following is address 'a' points to
 [1] 0x05cf2798
 b=a
 b[1]=1
 tracemem[0x05cf2798 - 0x05cf2750]:
 tracemem[0x05cf2750 - 0x05ed8ba0]:

 I don't understand what these addresses mean. Would you please help me
 understand it?

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.