Re: [R] Is it possible to avoid copying arrays when calling list()?

2013-08-17 Thread MRipley
Thanks for the input, but it looks like I found a simple solution. Turns out that if you assign to lists by name, then R doesn't make extra copies: x-double(10^9) mylist-list() system.time(mylist[[1]]-x) user system elapsed 2.992 3.352 6.364 x-double(10^9) mylist-list()

[R] Is it possible to avoid copying arrays when calling list()?

2013-08-16 Thread MRipley
Usually R is pretty good about not copying objects when it doesn't need to. However, the list() function seems to make unnecessary copies. For example: system.time(x-double(10^9)) user system elapsed 1.772 4.280 7.017 system.time(y-double(10^9)) user system elapsed 2.564

Re: [R] Is it possible to avoid copying arrays when calling list()?

2013-08-16 Thread Gang Peng
If you don't want to copy the data, you can use environments. You can first define x and y in the global environment and then in the function, use function get() to get x, y in the global environment. When you change x and y in the function, x and y also change in the global environment. Best,

Re: [R] Is it possible to avoid copying arrays when calling list()?

2013-08-16 Thread David Winsemius
On Aug 16, 2013, at 2:23 PM, Gang Peng wrote: If you don't want to copy the data, you can use environments. You can first define x and y in the global environment and then in the function, use function get() to get x, y in the global environment. When you change x and y in the function, x