eval_dirty: Evaluate expressions

Description Usage Arguments Details Value Examples

View source: R/language.R

Description

Evaluate expressions

Usage

1
eval_dirty(expr, env = parent.frame(), data = NULL, quoted = TRUE)

Arguments

expr

R expression or 'rlang' quo

env

environment to evaluate

data

dataframe or list

quoted

Is the expression quoted? By default, this is TRUE. This is useful when you don't want to use an expression that is stored in a variable; see examples

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.

Value

the executed results of expr evaluated with side effects.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
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

eval_dirty(quote({a <- 111}), env)
print(env$a)  # 111, a is changed

# Unquoted case
eval_dirty({a <- 222}, env, quoted = FALSE)
print(env$a)

dipsaus documentation built on Sept. 6, 2021, 5:08 p.m.