f_interp {lazyeval} | R Documentation |
Interpolate a formula
Description
Interpolation replaces sub-expressions of the form uq(x)
with
the evaluated value of x
, and inlines sub-expressions of
the form uqs(x)
.
Usage
f_interp(f, data = NULL)
uq(x, data = NULL)
uqf(x)
uqs(x)
Arguments
f |
A one-sided formula. |
data |
When called from inside |
x |
For |
Theory
Formally, f_interp
is a quasiquote function, uq()
is the
unquote operator, and uqs()
is the unquote splice operator.
These terms have a rich history in LISP, and live on in modern languages
like http://docs.julialang.org/en/release-0.1/manual/metaprogramming/
and https://docs.racket-lang.org/reference/quasiquote.html.
Examples
f_interp(x ~ 1 + uq(1 + 2 + 3) + 10)
# Use uqs() if you want to add multiple arguments to a function
# It must evaluate to a list
args <- list(1:10, na.rm = TRUE)
f_interp(~ mean( uqs(args) ))
# You can combine the two
var <- quote(xyz)
extra_args <- list(trim = 0.9)
f_interp(~ mean( uq(var) , uqs(extra_args) ))
foo <- function(n) {
~ 1 + uq(n)
}
f <- foo(10)
f
f_interp(f)
[Package lazyeval version 0.2.2 Index]