Created
June 17, 2015 20:32
-
-
Save leeper/524707845ae7a45d821f to your computer and use it in GitHub Desktop.
Play around with active bindings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mab <- function(obj, expr, envir = .GlobalEnv) { | |
makeActiveBinding(obj, | |
function(e) { | |
if(missing(e)) { | |
eval(parse(text = force(expr)), envir = envir) | |
} else { | |
makeActiveBinding(force(obj), function(expr) eval(parse(text = force(e)), envir = force(envir)), force(envir)) | |
} | |
}, | |
env = envir) | |
} | |
e <- new.env(parent = baseenv()) | |
e$a <- 1:3 | |
mab("b", "a*2", envir = e) | |
e$b | |
rm(a, envir = e) | |
e$b | |
e$a <- 5:1 | |
e$b | |
e$b <- "a*3" | |
e$b | |
e$b <- "a+0.5" | |
e$b | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment