[R] variable scope
Rui Barradas
ruipbarradas at sapo.pt
Tue Aug 28 20:41:40 CEST 2012
Hello,
Maybe local().
Continue your example with
#?local
local(for (i in 1:10) {
x <- vector(length=100000000)
})
ls() # not 'i' nor 'x'
Hope this helps,
Rui Barradas
Em 28-08-2012 19:29, Sam Steingold escreveu:
> At the end of a for loop its variables are still present:
>
> for (i in 1:10) {
> x <- vector(length=100000000)
> }
> ls()
>
> will print "i" and "x".
> this means that at the end of the for loop body I have to write
>
> rm(x)
> gc()
>
> is there a more elegant way to handle this?
>
> Thanks.
>
More information about the R-help
mailing list