cohortflow 0.0.0.9017
Documentation
- cohortflow has a hex logo.
- The website has an LLM use statement (
vignettes/articles/llm-use.Rmd) saying which AI coding assistants were used, for what, and how their output was checked. It is linked from the home-page sidebar and every page footer.
New features
- New
as_narrative()writes the attrition cascade as a paragraph for a methods section: “Of 200 participants assessed for eligibility, 16 (8.0%) were excluded: age missing (n = 10) and under 18 (n = 6). …” The numbers come fromas_attrition_tibble(), and after arandomise()step from the same per-arm counts asas_consort_diagram(), so the text agrees with the table and diagram. There is one sentence per category (or per step), each step described by itsreason(an inclusion step without one readsnot meeting "<label>"), per-arm sentences after randomisation, and a final-cohort sentence broken down by arm.count_bycounts units as in the table;unitsets the noun;style = "bullets"gives one sentence per line. The result prints wrapped to the console and drops into R Markdown and Quarto documents as text.
cohortflow 0.0.0.9016
Breaking changes
- CONSORT diagrams put every number beside text that describes those people. An uncategorised
exclude()orgroup_exclude()step’s label now appears in its exclusion box with the number removed (“Withdrew consent (n=4)”), and the main box below it reads “Remaining (n=118)”. Previously the main box showed “Withdrew consent (n=118)”, which read as 118 withdrawals. The newremaining_labelargument changes that text.include()-type steps keep their label on the main box. -
count_bynow counts distinct units in every box and row, not only the arm boxes and columns. Inas_attrition_tibble(),as_attrition_table()andas_consort_diagram(),n,n_removedand the percentages all count units, so a crossover trial reports participants throughout instead of participant-periods in the trunk and participants in the arms. A unit counts as removed at the step where it loses its last row.count_bymust name a level of the flow’s hierarchy (a level name, or the column of a single-column level), so the flow needsapply_criteria(hierarchy = ). Old calls without a hierarchy, or naming a column that is not a level, fail with an error (classcohortflow_count_by_hierarchy) that explains the change and shows thecf_hierarchy()call to add.
New features
-
include(),exclude(),group_include(),group_exclude(),select_within()andcf_criterion()gainreason: a description of the rows the step removes (“Under 18” forinclude(~ age >= 18, "Aged 18 or over")). Diagram exclusion boxes use it. Exclusion steps default to their label. An inclusion step without one gets an exclusion box that says “Excluded”. If it is listed in a category’s exclusion box, its label is used andas_consort_diagram()warns (classcohortflow_missing_reason, at most every 8 hours;options(cohortflow.warn_missing_reason = FALSE)turns it off).reasonis printed with the pipeline and round-trips throughexport_criteria()/import_criteria(); it is written only when set, so other files are unchanged. Flows built beforereasonexisted still draw. -
count_byno longer requiresbranch_by, and works with arandomise()split (each arm’s cascade counts the same units as the trunk).
Better messages for old usage
- A step selector such as
steps = c(0, "Consented")turns0into the text"0", which matches no step. The error now says so and suggestslist(0, "Consented"). This applies wherever steps are selected (cohort(),excluded(),as_characteristics_tibble(),stack_cohorts()). A step labelled"1"still resolves by label. -
import_criteria()warns (classcohortflow_legacy_yaml) when a file uses the pre-0.0.0.9011fn_argsformat, naming the step, explaining that default argument values were not stored, and giving the call to re-save the file. A file with a schemaversionnewer than 1 is refused with a message to update the package, instead of being misread. - The
mock_cohortflow()deprecation warning lists which generator suits which design, and has classcohortflow_deprecated.
cohortflow 0.0.0.9015
Documentation
- New package website at https://mattmoo.github.io/cohortflow/, with a reference index grouped by task and eight articles.
- Three vignettes: “Get started”, “Writing criteria” (including a worked example of how
include()andexclude()treat missing values) and “Hierarchical and cluster designs”. - Web-only articles: “Attrition tables”, “CONSORT diagrams”, “Staged pipelines and missing units”, “Describing who was excluded” and a “Study design gallery” covering parallel, crossover, cluster and stepped-wedge trials.
- Reference pages cross-link related functions, and
export_criteria(),import_criteria(),plot.cf_flow()andprint.consort_diagram()gain examples.
Bug fixes
-
as_consort_diagram(stage_by = )no longer draws stage boxes on top of each other. Stages (e.g. crossover periods) now stack below their branch box with the same gap as the rest of the diagram, and a wrapped label pushes later stages down instead of overlapping them. - The gt backend of
as_attrition_table()andas_characteristics_table()now leaves empty cells blank, as flextable and huxtable do. Previously it printedNAin the header row’s removed count and in every arm column above the final row. -
as_attrition_table(levels = NULL)now shows every hierarchy level, as documented and asas_attrition_tibble(levels = NULL)does. Previously it failed with an internal subsetting error.
cohortflow 0.0.0.9014
New features
-
excluded()gainsonly = FALSE. Withonly = TRUEit returns just the rows removed at the selected step, rather than every row removed up to and including it:excluded(flow, at = 2, only = TRUE).
cohortflow 0.0.0.9013
New features
-
save_consort_diagram()writes a CONSORT diagram (or acf_flow, drawn with default settings) to PNG, TIFF, JPEG, PDF, SVG or EPS, choosing the format from the file extension. Defaults suit manuscript submission: 300 dpi, a white background,raggdevices for raster output when installed,cairo_pdf()for PDF (embeds fonts), andsvglitefor SVG when installed. Whenwidthandheightare omitted the page size comes from the diagram layout, so box text fits its boxes and longer pipelines give taller files; supplying one dimension keeps the aspect ratio.
Bug fixes
-
as_attrition_table()now shows every percentage todigitsdecimal places, keeping trailing zeros: a 10% removal reads10.0%rather than10%, and the final row90.0% included. This applies to plain,group_x/group_yandlevels =tables, matchingas_consort_diagram().
cohortflow 0.0.0.9012
New features
-
as_characteristics_tibble()andas_characteristics_table()build a step-wise baseline-characteristics (“Table 1”) table: variables as rows, one column per criteria step, each cell summarising the cohort surviving up to and including that step (cohort(flow, step_number = k)). Numeric variables show mean (SD) and/or median [Q1, Q3]; factor, character and logical variables show n (%); each variable gets a missing-values row.steps =takes the same selectors ascohort()to restrict or reorder the columns,excluded = TRUEdescribes the rows removed at each step instead, andlevel =summarises one row per hierarchy unit. The table renders through the same flextable, gt and huxtable backends asas_attrition_table(). -
stack_cohorts()returns the per-step cohorts stacked with astepfactor, ready forgtsummary::tbl_summary(by = step).
cohortflow 0.0.0.9011
Smoke-test fixes
- Error messages from
cf_criterion()and the criterion evaluators no longer show raw markup such as{.arg label}; they now include the actual label, class, lengths and missing column names. - Per-level hierarchy counts (
as_attrition_tibble(levels = ),as_attrition_table(levels = )) no longer count anNAkey as a unit. For example, an expected participant with no cluster counts as one participant and zero clusters, not as an extra “phantom” cluster. - The
.dataand.envpronouns now work ininclude(),exclude()andselect_within()formulas, as they already did in grouped steps and ascheck_criteria()assumed. -
export_criteria()no longer errors on a primitive-function predicate such asinclude(is.na, ...). Such predicates now print as.Primitive("is.na")rather thanNULL. -
as_attrition_tibble(),as_attrition_table()andas_consort_diagram()now give a clear error (“branch_bymust be a single column name.”) whenbranch_by,count_by,stage_by,stage_label_by,group_xorgroup_yis not a single column name. Previously this failed with an R internals error. -
as_consort_diagram()now draws a plain linear cascade when no rows reach the branch point (a zero-row flow, or every row excluded beforerandomise()). Previously it warned, or withbranch_byfailed. - A row-wise predicate in
group_include()/group_exclude()(e.g.~ age > 18) now gives “Group criterion”
Audit fixes
-
NAvalues inbranch_by/stage_by(includingrandomise()arms) now form their own branch, labelled by the newbranch_na_labelargument (default"Missing") ofas_attrition_tibble(),as_attrition_table()andas_consort_diagram(). Previously they were counted in every branch. -
apply_criteria()now aborts (instead of warning) when the row identifier (id, single or composite, or a pre-existing.cf_row_id) has duplicate orNAvalues, which silently corruptedcohort()/excluded(). - Group predicates must return a logical
.pass, thebycolumn(s), and exactly one row per group; anything else now aborts. - Rows with an
NAin anybycolumn are removed by every grouped step type (group_exclude()used to keep them). -
as_attrition_table()gainsgroup_na_label. - Function predicates print their body rather than
x$predicate. -
export_criteria()stores the full function source, so default argument values survive a YAML round-trip; thefn_argsfield is dropped (old files still import). It now returns the YAML visibly whenpath = NULL.import_criteria()documents that criteria files contain executable code. - A warning is issued when a category’s steps are not consecutive.
- CONSORT boxes are spaced by their content, so long pipelines and tall exclusion boxes no longer overlap.
- Zero-row flows no longer show
NaN% included. -
branch_byvalues that clash with standard column names (e.g."n") abort. - The always-
NAbranchcolumn is removed fromas_attrition_tibble()output. -
cf_criterion()aborts whenbyis given forinclude/exclude;as_consort_diagram()aborts whencount_byis given withoutbranch_by. -
mock_cohortflow()warns once per session.
New features
cohort()andexcluded()can stop at an intermediate step, returning the rows surviving (or removed) up to and including it. Select the step withstep_number(0= starting data),label, orcategory(last step in that category); or useat, which auto-selects (number, else label, else category). At most one selector may be given. Withcohort(flag = TRUE), attribution only covers steps up to the chosen step.New
criteria_status()returns one row per data row and one logical column per criterion, for auditing who failed what and for set/overlap plots of exclusion reasons.mode = "cumulative"follows the cascade (FALSEat the removing step,NA= not assessed afterwards);mode = "independent"evaluates every criterion on the full data. Options cover failure sets (sets = "fail"),NAhandling (na = "keep"/"false"/"drop"), column naming,keep_data, and output as a tibble, data.table or logical matrix.data.tableis a new suggested package.New
check_criteria(criteria, data)checks before evaluation that every formula predicate,byandarmsrefers only to columns indata, and aborts naming each offending step’s number, label and missing column(s).apply_criteria()andcontinue_criteria()run it automatically, so a forgottenjoinin a staged pipeline now fails up front instead of withobject 'x' not foundinside evaluation. Names bound in the formula’s environment are allowed; function predicates are not checked.cf_flowobjects record theidcolumn(s) passed toapply_criteria()(older flow objects still work).?include/?excludedocument how a predicate that evaluates toNAis handled:include()removes the row,exclude()keeps it.as_attrition_table()gained alevelsargument, mirroringas_attrition_tibble(levels = ): it renders one row per criterion with a column block (N / Removed / % removed) per hierarchy level, so a single row reports its effect at both the unit of analysis and the unit of recruitment (e.g. participants and clusters) side by side. This is the reporting form required by the CONSORT cluster extension (Campbell, Elbourne & Altman, BMJ 2004;328:702-8) and the within-person extension. Newlevel_labelsargument supplies display names for the column blocks (level names are otherwise used as-is, unmangled). Ashow_consequentialargument adds an optional fourth column per level for units lost only because agroup_include()/group_exclude()group they belonged to was removed; by default it appears only when populated.levelscannot be combined withgroup_x/group_y/branch_by/count_by. Shading (shade/shade_fn) is computed per level.