A cf_criterion represents one inclusion or exclusion step in a cohort
eligibility pipeline. Five step types are supported (see type). The
predicate is always a
one-sided formula or a function; the interpretation depends on
the step type.
Usage
cf_criterion(
predicate,
label,
type = c("include", "exclude", "group_include", "group_exclude", "select_within",
"randomise"),
by = NULL,
category = NULL,
arms = NULL,
reason = NULL
)Arguments
- predicate
A one-sided formula or a function.
For
include/exclude: evaluated row-wise; must return a logical vector of lengthnrow(data).For
group_include/group_exclude: evaluated in adplyr::summarise()context per group (defined byby); must return a scalar logical. The result is broadcast back to all rows in each group.For
select_within: evaluated per group; must return a logical vector identifying which rows within the group to keep.For
randomise: must beNULL(a randomise step never removes rows).
Formula predicates are evaluated with a data mask, so the rlang pronouns work in every step type:
.data$agealways refers to the column and.env$ageto a variable in the formula's environment, which avoids ambiguity when a column and a local variable share a name.- label
A short human-readable description of this criterion.
- type
One of
"include","exclude","group_include","group_exclude","select_within", or"randomise".- by
For grouped step types (
group_include,group_exclude,select_within): one or more character strings naming the grouping column(s); supply more than one for composite (multi-column) grouping. Forrandomise: one or more character strings naming the randomisation unit column(s) (e.g."cluster_id"). Must beNULLfor the row-wise types (include,exclude). Rows with anNAin anybycolumn cannot be assigned to a group and are always removed by grouped step types.- category
An optional character string grouping this criterion with others for display purposes (e.g.
"Valid age"to group age-related steps into one box in a CONSORT diagram).NULL(default) leaves the step uncategorised (NAin output).- arms
For
type = "randomise"only: a single character string naming the column in the data that holds each unit's allocated arm (e.g."arm"). Used byas_consort_diagram()/as_attrition_tibble()to defaultbranch_bywhen not explicitly supplied. Must beNULLfor all other types.- reason
An optional short description of the rows this step removes, used wherever removals are listed: the exclusion boxes of
as_consort_diagram().NULL(default) falls back tolabelfor the exclusion types (exclude,group_exclude), whose label already describes the removed rows. Forinclude,group_includeandselect_withinthe label describes the rows kept, so setreason(e.g.label = "Aged 18 or over", reason = "Under 18"). Must beNULLforrandomise. See the Labels section ofinclude().
See also
Other criteria builders:
cf_criteria(),
check_criteria(),
exclude(),
group_exclude(),
group_include(),
include(),
randomise(),
select_within()
Examples
# Row-wise inclusion
cf_criterion(~ age >= 18, label = "Adults only", type = "include")
#> [+][~] Adults only
#> age >= 18
# Grouped under a category, with the text shown for the rows it removes
cf_criterion(~ !is.na(age), label = "Age recorded",
type = "include", category = "Valid age", reason = "Age missing")
#> [+][~] Age recorded
#> !is.na(age)
#> removes: Age missing
# Group-level inclusion (clusters with >= 5 participants)
cf_criterion(
~ n() >= 5,
label = "Sufficient cluster size",
type = "group_include",
by = "cluster_id"
)
#> [+][~] Sufficient cluster size [by: cluster_id]
#> n() >= 5
# Select first operation per patient
cf_criterion(
~ consent_date == min(consent_date, na.rm = TRUE),
label = "Index operation",
type = "select_within",
by = "participant_id"
)
#> [>][~] Index operation [by: participant_id]
#> consent_date == min(consent_date, na.rm = TRUE)
# Randomisation marker (no predicate; excludes nothing)
cf_criterion(
predicate = NULL,
label = "Randomised",
type = "randomise",
by = "cluster_id",
arms = "arm"
)
#> [R][-] Randomised [by: cluster_id] [arms: arm]
#> <none>