Examples for 'rlang::inject'


Inject objects in an R expression

Aliases: inject

Keywords:

### ** Examples

# inject() simply evaluates its argument with injection
# support. These expressions are equivalent:
2 * 3
[1] 6
inject(2 * 3)
[1] 6
inject(!!2 * !!3)
[1] 6
# Injection with `!!` can be useful to insert objects or
# expressions within other expressions, like formulas:
lhs <- sym("foo")
rhs <- sym("bar")
inject(!!lhs ~ !!rhs + 10)
foo ~ bar + 10
<environment: 0x55ccfe31a058>
# Injection with `!!!` splices lists of arguments in function
# calls:
args <- list(na.rm = TRUE, finite = 0.2)
inject(mean(1:10, !!!args))
[1] 5.5

[Package rlang version 1.1.4 Index]