[R] Creating an environment for a function.
Rolf Turner
rolf at math.unb.ca
Thu Apr 13 21:56:16 CEST 2006
Brian Ripley wrote:
> Can I also suggest local()? This does a similar thing in a perhaps
> more natural way.
Sorry, I'm not with you. I'm slow, and as I said, I don't
really grok environments.
Let's look at a toy example. Suppose I want to create a function foo:
function(x){x^n}
and assign n the value of 4, say, in the environment of foo.
Duncan Murdoch's solution was to create a function make.foo:
make.foo <- function() {
n <- 4
foo <- function(x){x^n}
foo
}
and then execute
foo <- make.foo()
How would I go about accompishing the same (toy) task making use of the
local() function?
Thanks.
cheers,
Rolf
More information about the R-help
mailing list