Skip to content
Prev 46280 / 63461 Next

Understanding modification in place

On Jul 24, 2013, at 10:35 AM, Hadley Wickham wrote:

            
Did you look at source()? ;)
It has to do with all the additional processing there which assigns the result of every line locally thus producing extra copies. If you just eval it, you'll get the same behavior as in the console:
Global
@100816498 13 INTSXP g0c2 [NAM(1)] (len=3, tl=0) 1,2,3
@100816498 13 INTSXP g0c2 [NAM(1)] (len=3, tl=0) 1,1,3
In function
@102c42378 13 INTSXP g0c2 [NAM(1)] (len=3, tl=0) 1,2,3
@102c42378 13 INTSXP g0c2 [NAM(1)] (len=3, tl=0) 1,1,3

The same is true is you just put { } around it and source it so it becomes a single expression.

Cheers,
Simon