Last active
November 19, 2020 08:22
-
-
Save moodymudskipper/33a6628c105e87bd0f602effeac37184 to your computer and use it in GitHub Desktop.
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
decompose <- function(expr) { | |
expr <- substitute(expr) | |
funs <- setdiff(all.names(expr), all.vars(expr)) | |
wrapped <- list() | |
for (fun in funs) { | |
fun_env <- environment(get(fun, envir = parent.frame())) | |
if(is.null(fun_env)) | |
namespace <- "base" | |
else | |
namespace <- getNamespaceName(fun_env) | |
namespaced_fun <- paste0(namespace,"::`", fun, "`") | |
f <- as.function(c(alist(...=), bquote({ | |
sc <- sys.call() | |
sc_bkp <- sc | |
sc[[1]] <- quote(.(str2lang(namespaced_fun))) | |
res <- eval.parent(sc) | |
message(deparse(sc_bkp)) | |
print(res) | |
}))) | |
wrapped[[fun]] <- f | |
} | |
eval(expr, envir = wrapped, enclos = parent.frame()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment