Using functions and environments

后端 未结 3 2203
星月不相逢
星月不相逢 2020-12-09 13:52

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 accordi

3条回答
  •  醉酒成梦
    2020-12-09 14:47

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

    mind the parentheses:) The following will work:

    with(env, x)+z
    

提交回复
热议问题