Last active
June 13, 2022 21:54
-
-
Save moodymudskipper/bf8599cb5c539fb45b58d0c85f49c051 to your computer and use it in GitHub Desktop.
Revisions
-
moodymudskipper revised this gist
Jun 13, 2022 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -11,11 +11,12 @@ makeActiveBinding("v", local({ count <<- 1 e <<- exec_env } # fetch function and body call <- sys.call(-1) caller_env <- sys.frame(-2) f <- eval(call[[1]], caller_env) calls <- as.list(body(f))[-1] # assign vpos <- which(sapply(calls, function(x) identical(x, quote(v)))) value <- eval(calls[vpos - 1][[count]], exec_env) var <- as.character(calls[vpos + 1][count]) -
moodymudskipper created this gist
Jun 13, 2022 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,40 @@ makeActiveBinding("v", local({ e <- NULL count <- 1 function(value) { # increment or reinitialize counter exec_env <- sys.frame(-1) if(identical(e, exec_env)) { count <<- count + 1 } else { count <<- 1 e <<- exec_env } # call <- sys.call(-1) caller_env <- sys.frame(-2) f <- eval(call[[1]], caller_env) calls <- as.list(body(f))[-1] vpos <- which(sapply(calls, function(x) identical(x, quote(v)))) value <- eval(calls[vpos - 1][[count]], exec_env) var <- as.character(calls[vpos + 1][count]) assign(var, value, exec_env) } }), .GlobalEnv) test <- function() { 1 v x 1 + 1 v y c(x, y) } test() #> [1] 1 2