r - pass objects to nested functions using environments -


i want pass objects 1 function nested function assigning environments. below sample of code not work. how can happen assigning environments in function?

sumi <- function(x,y) {     my.env <- new.env()      my.env$rumi <- function() {         my.env$k <- x[1]         my.env$f <- y[1]     }     k <- get("k", my.env)     f <- get("f", my.env)     z <- k+f     return(z) } 

the code defines never runs rumi objects have created if run never are.

adding line marked ### works:

sumi <- function(x,y) {     my.env <- new.env()      my.env$rumi <- function() {         my.env$k <- x[1]         my.env$f <- y[1]     }     my.env$rumi()  ###     k <- get("k", my.env)     f <- get("f", my.env)     z <- k+f     return(z) } sumi(1, 2) ## [1] 3 

Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -