Applies additional criteria steps to the surviving cohort of an existing
cf_flow, optionally joining on new columns first. This lets an
attrition pipeline be built up in stages – e.g. apply screening criteria,
then join newly collected follow-up data and continue with further
criteria – while keeping a single, continuous step numbering and
denominators that correctly reflect the cohort at each stage (rather than
restarting counts from the original data).
Arguments
- flow
A
cf_flowobject produced byapply_criteria()(or a previous call tocontinue_criteria()).- criteria
A
cf_criteriaobject with the additional steps to apply. If empty (length(criteria) == 0),flowis returned unchanged.- join
Optional data frame of new columns to attach before evaluating
criteria, e.g. follow-up data collected after the initial screening. Joined onto all offlow's original rows (via a left join), so rows already excluded at an earlier stage also gain the new columns (asNAwherejoinhas no match) – this keeps the full row history intact. Requiresby.- by
Column name(s) shared by
flow's data andjoin, used to join them. Required, and only used, whenjoinis supplied.
Value
A cf_flow object whose criteria and steps are the
concatenation of flow's existing pipeline and criteria, with step
numbers continuing on from flow.
Details
Before any new step is evaluated, check_criteria() verifies that every
step refers only to columns present in flow's data plus join, so a
forgotten join fails up front naming the step and the missing column(s).
See also
Other pipeline:
apply_criteria(),
cf_expected(),
cf_hierarchy()
Examples
dat <- mock_parallel_rct(n_participants = 200, seed = 1)
crit <- cf_criteria() |>
include(~ eligible_screen, label = "Passed screening")
flow <- apply_criteria(dat, crit)
#> No `id` supplied and no `.cf_row_id` column found. Adding a sequential `.cf_row_id`.
more_crit <- cf_criteria() |>
include(~ !is.na(consent_date), label = "Consent recorded")
flow2 <- continue_criteria(flow, more_crit)
flow2
#> Cohort flow (2 steps | 200 -> 157 rows | 43 excluded)
#> ------------------------------------------------------------
#> 1. [+] Passed screening
#> n_in: 200 kept: 183 removed: 17
#> 2. [+] Consent recorded
#> n_in: 183 kept: 157 removed: 26