eval_conditions: Evaluate conditions

View source: R/cnd_df.R

eval_conditionsR Documentation

Evaluate conditions

Description

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.

Usage

eval_conditions(dat, ..., .na = NA, .env = rlang::caller_env())

Arguments

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.

.na

Return value to be used when the conditions evaluate to NA.

.env

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.

Value

A logical vector reflecting matching rows in dat.


sdtm.oak documentation built on April 3, 2025, 9:37 p.m.