Skip to content

Instantly share code, notes, and snippets.

@datalove
Last active August 29, 2015 14:05
Show Gist options
  • Save datalove/b3becb12301a9508cbae to your computer and use it in GitHub Desktop.
Save datalove/b3becb12301a9508cbae to your computer and use it in GitHub Desktop.
How to get R to evaluate arbitrary code in a string
rm(list=ls())
rcode <- "x <- 1+1; y <- 2+2"
# running `eval` evaluates `rcode` into the parent environment
eval(parse(text = rcode))
print(x)
print(y)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment