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 relevant information is incorporated into the expression.
partial_eval(call, vars = character(), env = caller_env())
an unevaluated expression, as produced by
character vector of variable names.
environment in which to search for local values
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% perfectly.
partial_eval() uses the following heuristic:
If the tbl variables are known, and the symbol matches a tbl variable, then remote.
If the symbol is defined locally, local.
You can override the guesses using
remote() to force
computation, or by using the
.env pronouns of tidy evaluation.
#> year > 1980#> id %in% c("ansonca01", "forceda01", "mathebo01")# cf. partial_eval(quote(id == .data$ids), vars = vars)#> id == ids# You can use local() or .env to disambiguate between local and remote # variables: otherwise remote is always preferred year <- 1980 partial_eval(quote(year > year), vars = vars)#> year > year#> year > 1980partial_eval(quote(year > .env$year), vars = vars)#> year > 1980# 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)), vars = vars)#> year > f(1980)#> year > 1981# For testing you can also use it with the tbl omitted partial_eval(quote(1 + 2 * 3))#> 1 + 2 * 3x <- 1 partial_eval(quote(x ^ y))#> 1^y