Skip to content

Add structured group columns to tidy_pool_obj() output - #53

Open
bailliem wants to merge 6 commits into
mainfrom
51-tidy_pool_obj-output-format
Open

Add structured group columns to tidy_pool_obj() output#53
bailliem wants to merge 6 commits into
mainfrom
51-tidy_pool_obj-output-format

Conversation

@bailliem

@bailliem bailliem commented Jul 30, 2026

Copy link
Copy Markdown
Collaborator

Closes #51

Note: intended to merge after #52 — trivial NEWS.md/inst/WORDLIST conflicts will be resolved by updating this branch from main once #52 lands.

Summary

tidy_pool_obj() output is now programmer-friendly and structured, addressing the concerns raised in #51:

  • Three new columns, added additively: group_var, group_level_1, group_level_2. All ten existing columns keep their names, order, and default-call values byte-identical — pool_to_ard(), efficacy_table(), and any external consumers are unaffected (regression-verified).
  • New optional vars / data arguments: when supplied, the generic ref/alt labels are replaced with real treatment-group names (group_var = "TRT", levels "Drug A" / "Placebo"; reference = first factor level, matching rbmi convention), and descriptions upgrade to the style proposed in the issue: "Difference: Drug A vs Placebo at Week 24".
  • Safety guards (warn + fall back to placeholders, never error): only one of vars/data supplied; missing/malformed vars$group; group variable with ≠ 2 levels; and a non-factor group column — the last prevents silently alphabetized (i.e. swapped) treatment labels.
  • NSE column bindings registered; docs and NEWS updated.

The parameter_type "trt""contrast" vocabulary rename from the issue is deliberately deferred: it is a breaking change (efficacy_table(), plot_forest(), pool_to_ard(), and the tidy filters all switch on the current values) and is planned for the release that deprecates the legacy columns.

Test plan

  • 27 new assertions in test-tidiers.R: placeholder semantics, byte-identical legacy columns, enrichment with real names, upgraded descriptions, and all four guard paths (including character group column and malformed vars$group).
  • Consumer regression: test-ard_conversion.R (300) and test-efficacy_table.R (48) pass unchanged.
  • devtools::check(): 0 errors, 0 warnings (environmental NOTEs only). Full suite: 1064 passing, 0 failures.

bailliem added 6 commits July 30, 2026 12:34
Add placeholder group columns (group_var, group_level_1, group_level_2) to
tidy_pool_obj() output. Placeholders default to NA for group_var, lsm_type/alt for
group_level_1 (lsm/trt rows), and NA/ref for group_level_2 (lsm/trt rows).
Task 2 will replace placeholders with real names when enrichment inputs present.
Add optional vars/data arguments to tidy_pool_obj() that map ref/alt
placeholders in group_level_1/2 to real group names (and group_var to
the real column name) when exactly two group levels are present.
Descriptions are upgraded accordingly. Falls back to placeholders with
a cli_warn() when vars/data are missing, incomplete, or the group
variable does not have exactly two levels.

Uses as.factor() rather than factor() when counting group levels so
unused factor levels are not silently dropped (factor() on an
already-factor column re-derives levels from observed values only).
- Warn and fall back to placeholder group columns when the group
  variable is not a factor, instead of silently deriving ref/alt via
  alphabetical sort on a coerced character column (could reverse
  treatment labels).
- Make the vars$group validity guard robust to NULL, non-character,
  and length != 1 values so malformed input warns instead of erroring.
- Add regression tests for both fixes and for two previously-untested
  guard arms (vars$group absent from data; data supplied without vars).
- Fix NEWS.md heading case and @return wording for group_var to match
  repo convention; regenerate man/tidy_pool_obj.Rd.
@bailliem bailliem linked an issue Jul 30, 2026 that may be closed by this pull request
@bailliem bailliem self-assigned this Jul 30, 2026
@bailliem
bailliem marked this pull request as ready for review July 30, 2026 14:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

tidy_pool_obj() output format.

1 participant