tidy_interp

0th

Percentile

Process unquote operators in a captured expression.

While all capturing functions in the tidy evaluation framework perform unquote on capture (most notably tidy_quote()), tidy_interp() manually processes unquoting operators in expressions that are already captured. tidy_interp() should be called in all user-facing functions expecting a formula as argument to provide the same quasiquotation functionality as NSE functions.

Usage
tidy_interp(x, env = NULL)
Arguments
x
A function, raw expression, or formula to interpolate.
env
The environment in which unquoted expressions should be evaluated. By default, the formula or closure environment if a formula or a function, or the current environment otherwise.
Aliases
  • tidy_interp
Examples
# All tidy NSE functions like tidy_quote() unquote on capture:
tidy_quote(list(!! 1 + 2))

# tidy_interp() is meant to provide the same functionality when you
# have a formula or expression that might contain unquoting
# operators:
f <- ~list(!! 1 + 2)
tidy_interp(f)

# Note that only the outer formula is unquoted (which is a reason
# to use tidy_interp() as early as possible in all user-facing
# functions):
f <- ~list(~!! 1 + 2, !! 1 + 2)
tidy_interp(f)


# Another purpose for tidy_interp() is to interpolate a closure's
# body. This is useful to inline a function within another. The
# important limitation is that all formal arguments of the inlined
# function should be defined in the receiving function:
other_fn <- function(x) toupper(x)

fn <- tidy_interp(function(x) {
  x <- paste0(x, "_suffix")
  !!! body(other_fn)
})
fn
fn("foo")
Documentation reproduced from package rlang, version 0.0.0.9000, License: GPL-3

Community examples

Looks like there are no examples yet.