% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/tidyeval.R
\name{partial_eval}
\alias{partial_eval}
\title{Partially evaluate an expression.}
\usage{
partial_eval(call, data, env = caller_env(), error_call = caller_env())
}
\arguments{
\item{call}{an unevaluated expression, as produced by \code{\link[=quote]{quote()}}}

\item{data}{A lazy data frame backed by a database query.}

\item{env}{environment in which to search for local values}
}
\description{
This function partially evaluates a quosure yielding an expression. It
uses information from the current \code{tbl} and the local environment to yield
a standalone expression. This simplifies SQL translation because we can just
pass around expressions rather than expressions + environments
(i.e. quosures).
}
\section{Symbol substitution}{


\code{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. \code{partial_eval()} uses the following heuristic:

\itemize{
\item If the tbl variables are known, and the symbol matches a tbl
variable, then remote.
\item If the symbol is defined locally, local.
\item Otherwise, remote.
}

You can override the guesses using \code{local()} and \code{remote()} to force
computation, by using the \code{.data} and \code{.env} pronouns of tidy evaluation,
or by using dbplyr's own \code{.sql} pronoun.
}

\examples{
lf <- lazy_frame(year = 1980, id = 1)
partial_eval(quote(year > 1980), data = lf)

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

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

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

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

# You can use `.sql` to make it clear that the function comes from SQL,
# and inside a package, reduce the number of globalVariables() directives
# needed
partial_eval(quote(.sql$EXTRACT_YEAR(year)), lf)
}
\keyword{internal}
