Using functions and environments

Posted by Eduardo Leoni on Stack Overflow See other posts from Stack Overflow or by Eduardo Leoni
Published on 2010-04-15T14:55:53Z Indexed on 2010/04/15 15:13 UTC
Read the original article Hit count: 165

Filed under:
|

Following the recent discussions here (e.g. 1, 2 ) I am now using environments in some of my code. My question is, how do I create functions that modify environments according to its arguments? For example:

y <- new.env()
with(y, x <- 1)
f <- function(env,z) {
    with(env, x+z)
}
f(y,z=1)

throws

Error in eval(expr, envir, enclos) : object 'z' not found

I am using environments to keep concurrently two sets of simulations apart (without refactoring my code, which I wrote for a single set of experiments).

© Stack Overflow or respective owner

Related posts about r

    Related posts about scope