Skip to content
Prev 47216 / 398500 Next

Deep copy in R

On Mon, 5 Apr 2004, Shin, Daehyok wrote:

            
There will be a copy at line 5 and at line 6 or line 7 or both.

Copying occurs when there are (or could be) two references to an object
and one of them is modified.

Passing v to the function f creates a second reference to it (the local
variable x), and then y is a third reference. Modifying y forces a copy so
that x and v don't get modified

The data.frame() call need not copy, but I think it actually does. If it
does, modifying xf$x need not copy.

Returning y does not copy, and xf is discarded for garbage collection when
the function exits.


	-thomas