partial_eval: Partially evaluate an expression.

View source: R/partial_eval.R

partial_evalR Documentation

Partially evaluate an expression.

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 translation because expressions don't need to carry around their environment - all relevant information is incorporated into the expression.

Usage

partial_eval(call, vars = character(), env = caller_env())

Arguments

call

an unevaluated expression, as produced by quote()

vars

character vector of variable names.

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).

You can override the guesses using local() and remote() to force computation, or by using the .data and .env pronouns of tidy evaluation.

Examples

vars <- c("year", "id")
partial_eval(quote(year > 1980), vars = vars)

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

# cf.
partial_eval(quote(id == .data$ids), vars = vars)

# 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)
partial_eval(quote(year > local(year)), vars = vars)
partial_eval(quote(year > .env$year), vars = vars)

# 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)
partial_eval(quote(year > local(f(1980))), vars = vars)

AzureKusto documentation built on Oct. 12, 2023, 5:11 p.m.