File: f_interp.Rd

package info (click to toggle)
r-cran-lazyeval 0.2.2-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 596 kB
  • sloc: ansic: 310; sh: 9; makefile: 2
file content (60 lines) | stat: -rw-r--r-- 1,494 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/f-interp.R
\name{f_interp}
\alias{f_interp}
\alias{uq}
\alias{uqs}
\alias{uqf}
\title{Interpolate a formula}
\usage{
f_interp(f, data = NULL)

uq(x, data = NULL)

uqf(x)

uqs(x)
}
\arguments{
\item{f}{A one-sided formula.}

\item{data}{When called from inside \code{f_eval}, this is used to pass on
the data so that nested formulas are evaluated in the correct environment.}

\item{x}{For \code{uq} and \code{uqf}, a formula. For \code{uqs}, a
a vector.}
}
\description{
Interpolation replaces sub-expressions of the form \code{uq(x)} with
the evaluated value of \code{x}, and inlines sub-expressions of
the form \code{uqs(x)}.
}
\section{Theory}{

Formally, \code{f_interp} is a quasiquote function, \code{uq()} is the
unquote operator, and \code{uqs()} is the unquote splice operator.
These terms have a rich history in LISP, and live on in modern languages
like \href{Julia}{http://docs.julialang.org/en/release-0.1/manual/metaprogramming/}
and \href{Racket}{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)
}