# NOT RUN {
# eval_bare() works just like base::eval():
env <- child_env(NULL, foo = "bar")
expr <- quote(foo)
eval_bare(expr, env)
# To explore the consequences of stack inconsistent semantics, let's
# create a function that evaluates `parent.frame()` deep in the call
# stack, in an environment corresponding to a frame in the middle of
# the stack. For consistency we R's lazy evaluation semantics, we'd
# expect to get the caller of that frame as result:
fn <- function(eval_fn) {
list(
returned_env = middle(eval_fn),
actual_env = get_env()
)
}
middle <- function(eval_fn) {
deep(eval_fn, get_env())
}
deep <- function(eval_fn, eval_env) {
expr <- quote(parent.frame())
eval_fn(expr, eval_env)
}
# With eval_bare(), we do get the expected environment:
fn(rlang::eval_bare)
# But that's not the case with base::eval():
fn(base::eval)
# Another difference of eval_bare() compared to base::eval() is
# that it does not insert parasite frames in the evaluation stack:
get_stack <- quote(identity(ctxt_stack()))
eval_bare(get_stack)
eval(get_stack)
# }
Run the code above in your browser using DataLab