[R] Creating an environment for a function.
Gabor Grothendieck
ggrothendieck at gmail.com
Fri Apr 14 00:14:27 CEST 2006
If you think of n and the function as components of an object
then you could use the proto package to define an object, p,
that contains those two components. If we assume no
children of p are required (from your description I assume
that that is the case) then its just:
library(proto)
p <- proto(n = 4, f = function(., x) x^n)
p$f(2) # 16
# we can later change the value of n
p$n <- 3
p$f(2) # 8
On 4/13/06, Rolf Turner <rolf at math.unb.ca> wrote:
> Thomas Lumley wrote:
>
> > foo <- local({
> > n <- 4
> > function(x) {x^n}
> > })
>
> Bewdy! Thanks a lot. Slowly but slowly ( :-) ) I learn things!
>
> cheers,
>
> Rolf
>
> ______________________________________________
> R-help at 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
>
More information about the R-help
mailing list