rlang (version 0.0.0.9000)

tidy_eval_env: Create a tidy evaluation environment.

Description

This is useful when want to use the tidy evaluation framework in your own evaluating functions. The returned environment has elements of data in scope, the .env and .data pronouns, and treats formulas as self-evaluating promises. See tidy_eval() and tidy_quote() for more information.

Usage

tidy_eval_env(env = base_env(), data = NULL)
tidy_eval_env_cleanup(eval_env)

Arguments

env
The original scope.
data
Additional data to put in scope.
eval_env
A tidy evaluation env to clean up.

Details

Once an expression has been evaluated in the tidy environment, it's a good idea to clean up the definitions that make self-evaluation of formulas possible tidy_eval_env_cleanup(). Otherwise your users may face unexpected results in specific corner cases (see examples).

Examples

Run this code
# Evaluating in a tidy evaluation environment enables all tidy
# features:
env <- tidy_eval_env(data = mtcars)
eval(quote(list(.data$cyl, ~letters)), env)

# However you need to cleanup the environment after
# evaluation. Otherwise the leftover definitions for self-evaluation
# of formulas might cause unexpected results:
fn <- eval(quote(function() ~letters), env)
fn()

tidy_eval_env_cleanup(env)
fn()

Run the code above in your browser using DataCamp Workspace