eval_conditions()
evaluates a set of conditions in the context of a
data frame and an optional environment.
The utility of this function is to provide an easy way to generate a logical
vector of matching records from a set of logical conditions involving
variables in a data frame (dat
) and optionally in a supplementary
environment (.env
). The set of logical conditions are provided as
expressions to be evaluated in the context of dat
and .env
.
Variables are looked up in dat
, then in .env
, then in the calling
function's environment, followed by its parent environments.
eval_conditions(dat, ..., .na = NA, .env = rlang::caller_env())
A logical vector reflecting matching rows in dat
.
A data frame
A set of logical conditions, e.g. y & z, x | z
(x
, y
, z
would have to exist either as columns in dat
or in the environment
.env
). If multiple expressions are included, they are combined with the
&
operator.
Return value to be used when the conditions evaluate to NA
.
An optional environment to look for variables involved in logical
expression passed in ...
. A data frame or a list can also be passed that
will be coerced to an environment internally.