inject | R Documentation |
inject()
evaluates an expression with injection
support. There are three main usages:
Splicing lists of arguments in a function call.
Inline objects or other expressions in an expression with !!
and !!!
. For instance to create functions or formulas
programmatically.
Pass arguments to NSE functions that defuse their
arguments without injection support (see for instance
enquo0()
). You can use {{ arg }}
with functions documented
to support quosures. Otherwise, use !!enexpr(arg)
.
inject(expr, env = caller_env())
expr |
An argument to evaluate. This argument is immediately
evaluated in |
env |
The environment in which to evaluate |
# inject() simply evaluates its argument with injection
# support. These expressions are equivalent:
2 * 3
inject(2 * 3)
inject(!!2 * !!3)
# 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)
# Injection with `!!!` splices lists of arguments in function
# calls:
args <- list(na.rm = TRUE, finite = 0.2)
inject(mean(1:10, !!!args))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.