Skip to content
Prev 170144 / 398506 Next

Variables captured in closures get copied?

Peter Dalgaard wrote:
interesting.  i'm not sure if this is something one should consider
obvious, though it does make sense.
actually, it seems that r gets caught by surprise on such sort of semantics:

d = data,frame(x=1:10^8)
(function() d$x[1] = 0)()

prints 'Error: cannot allocate vector of size 762.9 Mb' and stops
responding with 100% cpu (sometimes even 101, as reported by top, hehe)
occupied by r.

platform       i686-pc-linux-gnu          
arch           i686                       
os             linux-gnu                  
system         i686, linux-gnu            
status                                    
major          2                          
minor          8.0                        
year           2008                       
month          10                         
day            20                         
svn rev        46754                      
language       R                          
version.string R version 2.8.0 (2008-10-20)

vQ