In C and variants, when you have something like this:
{ tmp1 <- 5 tmp2 <- 2 print(tmp1 + tmp2) }
7 will be printed, but the variables tmp1 and tmp2 will be removed from the stack after the completion of the area } . I sometimes need similar functionality in R, so I donβt need to clear (many) temporary variables at some point in time.
One way to make this work in R is this:
(function(){ tmp1 <- 5 tmp2 <- 2 print(tmp1 + tmp2) })()
Now it seems a little hacky - or it can only be me.
Are there any better or more concise (i.e. more readable) ways to do this in R?
source share