Skip to contents

The predicate is evaluated in a dplyr::summarise() context per group (when a formula) or receives a grouped data frame (when a function). Groups where the predicate returns TRUE are kept; all rows in failing groups are removed.

Usage

group_include(criteria, by, predicate, label, category = NULL, reason = NULL)

Arguments

criteria

A cf_criteria object (or NULL to start a new one).

by

One or more column names (character vector) to group by; supply more than one for composite (multi-column) grouping.

predicate

A one-sided formula using summary functions (n(), mean(), n_distinct(), etc.) or a function that receives a grouped data frame and returns a tibble with columns <by> and .pass.

label

A short human-readable description of this criterion.

category

An optional string grouping this step with others for display. NULL leaves it uncategorised.

reason

An optional short description of the rows this step removes, shown in diagram exclusion boxes. NULL (default) uses label for exclusion steps; for inclusion steps it should be set. See the Labels section.

Value

The updated cf_criteria object.

Examples

cf_criteria() |>
  group_include(by = "cluster_id", ~ n() >= 5, label = "Cluster size >= 5")
#> Cohort criteria pipeline  (1 step)
#>    1. [+][~] (group_include) [by: cluster_id] Cluster size >= 5
#>           n() >= 5