Skip to content

Instantly share code, notes, and snippets.

@jmbarbone
Last active September 29, 2021 21:02
Show Gist options
  • Save jmbarbone/77c46e414511d2d53e9835e7d130286c to your computer and use it in GitHub Desktop.
Save jmbarbone/77c46e414511d2d53e9835e7d130286c to your computer and use it in GitHub Desktop.
playing around with dumping variables
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