Evaluate expressions
Usage
eval_dirty(expr, env = parent.frame(), data = NULL, quoted = TRUE)
Details
eval_dirty
uses base::eval()
function to evaluate
expressions. Compare to rlang::eval_tidy
, which won't affect original
environment, eval_dirty
causes changes to the environment. Therefore
if expr
contains assignment, environment will be changed in this case.
Examples
env = new.env(); env$a = 1
rlang::eval_tidy(quote({a <- 111}), env = env)
print(env$a) # Will be 1. This is because eval_tidy has no side effect
#> [1] 1
eval_dirty(quote({a <- 111}), env)
print(env$a) # 111, a is changed
#> [1] 111
# Unquoted case
eval_dirty({a <- 222}, env, quoted = FALSE)
print(env$a)
#> [1] 222