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

From: Alberto Monteiro <albmont_at_centroin.com.br>
Date: Fri 20 Oct 2006 - 17:01:39 GMT

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



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Sat Oct 21 11:52:11 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Sat 21 Oct 2006 - 03:30:11 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.