[R] I really don't understand functions in R :-)

Alberto Monteiro albmont at centroin.com.br
Fri Oct 20 19:01:39 CEST 2006


Jim Holtman wrote:
>
> It sounds like you want to use 'local' to create private variables:
>
Ok, so, in a "real world" example, I should do something
like this:

n <- 3 # but here there is some very complex computations
# that give me a value for n
f <- local({
  f.n <- n
  function(x) x^f.n
})
f(2)
# 8
n <- 2
f(2)
# 8

Thanks for the enlightnment :-)

Alberto Monteiro



More information about the R-help mailing list