partial_eval: Partially evaluate an expression.

Description Usage Arguments Symbol substitution Examples

View source: R/partial-eval.r

Description

This function partially evaluates an expression, using information from the tbl to determine whether names refer to local expressions or remote variables. This simplifies SQL translation because expressions don't need to carry around their environment - all revelant information is incorporated into the expression.

Usage

1

Arguments

call

an unevaluated expression, as produced by quote

tbl

a tbl object

env

environment in which to search for local values

Symbol substitution

partial_eval needs to guess if you're referring to a variable on the server (remote), or in the current environment (local). It's not possible to do this 100

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
if (require("Lahman")) {
bdf <- tbl_df(Batting)
partial_eval(quote(year > 1980), bdf)

ids <- c("ansonca01", "forceda01", "mathebo01")
partial_eval(quote(id %in% ids), bdf)

# You can use local to disambiguate between local and remote
# variables: otherwise remote is always preferred
year <- 1980
partial_eval(quote(year > year), bdf)
partial_eval(quote(year > local(year)), bdf)

# Functions are always assumed to be remote. Use local to force evaluation
# in R.
f <- function(x) x + 1
partial_eval(quote(year > f(1980)), bdf)
partial_eval(quote(year > local(f(1980))), bdf)

# For testing you can also use it with the tbl omitted
partial_eval(quote(1 + 2 * 3))
x <- 1
partial_eval(quote(x ^ y))
}

sctyner/dplyr050 documentation built on May 17, 2019, 2:22 p.m.