Last active
September 29, 2021 21:02
-
-
Save jmbarbone/77c46e414511d2d53e9835e7d130286c to your computer and use it in GitHub Desktop.
playing around with dumping variables
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
foo <- function(script_text, file = tempfile(), varlist = list()) { | |
e <- list2env(varlist) | |
dump(names(e), file = file, envir = e) | |
s <- as.character(as.expression(substitute(script_text))) | |
cat(s, "\n", file = file, append = TRUE) | |
system2("rscript", c("--vanilla", file)) | |
} | |
foo({a <- mean(a); length(a)}, varlist = list(a = 1:10)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment