Description Usage Arguments Theory Examples
Interpolation replaces sub-expressions of the form uq(x)
with
the evaluated value of x
, and inlines sub-expressions of
the form uqs(x)
.
1 2 3 4 5 6 7 |
f |
A one-sided formula. |
data |
When called from inside |
x |
For |
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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | 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)
|
x ~ 1 + 6 + 10
~mean(1:10, na.rm = TRUE)
~mean(xyz, trim = 0.9)
~1 + uq(n)
<environment: 0x370bdc0>
~1 + 10
<environment: 0x370bdc0>
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.