Skip to content

Fix td_formula covariate parsing (tests + docs; fix via barry#26) - #12

Merged
gvegayon merged 3 commits into
masterfrom
fix/formula-covariate-parsing
Sep 26, 2026
Merged

gvegayon merged 3 commits into
masterfrom
fix/formula-covariate-parsing

Conversation

@gvegayon

@gvegayon gvegayon commented Sep 26, 2026 •

Copy link
Copy Markdown
Member

What

Why

td_formula() could build a different model from the one written, with no error:

Formula (order 1, Y = a, b) Before After
{y0} > {y0} x Day1 Motif {a+}>{a+, b+} x Day1 Motif {a+}>{a+} x Day1
{y0} > {y1}x Female Motif {a+}>{b+} (covariate dropped) Motif {a+}>{b+} x Female
{y0_1} > {y1} Motif {a+, b+} (not a transition) error
{y0} x Day5 error: column out of range works

The root cause: barry looked for y<col> tokens across the whole formula, including the covariate name.

Reviewer notes

  • Merge order: this PR can merge on its own. The new regression tests (test_formula_parser.R) first check which parser defm was compiled with, by trying {y0} > {y1} x Day1 (the old parser throws on it). If it fails they call exit_file(). This avoids depending on the installed barry version, which may differ from the headers defm was built against. Once Fix defm_motif_parser reading covariate names as motif terms USCbiostats/barry#26 and Sync headers from barry: fix defm formula parser covariate handling USCbiostats/barryr#12 are merged, CI installs barryr from GitHub (Remotes) and the tests run. I checked both paths locally: CRAN barry 0.2.2 gives 25/25 with the parser tests skipped, and barry 0.2.2.9000 gives 30/30.
  • Consider raising LinkingTo to barry (>= 0.2.3) once that is on CRAN.
  • Behavior change: "{...} xCovar" (no whitespace after x) is now a syntax error instead of being ambiguous.
  • Existing fitted models that used a covariate with y<digit> in its name, or }x, were estimating a different motif than intended and should be re-run.
  • Tests: tinytest::test_package("defm") gives 30/30 passing against the barryr branch.

🤖 Generated with Claude Code

gvegayon and others added 2 commits September 25, 2026 19:26
…ests

barry's formula parser read motif variables from the whole td_formula()
string, including the covariate, so a covariate named e.g. `Day1` silently
added `y1` to the motif. It also dropped the covariate in `{...}x Covar`
and turned `{y0_1} > {y1}` into an intercept motif (USCbiostats/barry#26).

- Require barry (>= 0.2.2.9000), which includes the fix.
- Add inst/tinytest/test_formula_parser.R covering these cases, including
  a check of the covariate-weighted statistic against a hand computation.
- Document the covariate syntax in td_formula().
- Bump to 0.2.2.9000 and add NEWS.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Requiring barry (>= 0.2.2.9000) broke CI: neither CRAN nor barryr's main
branch provides it yet (USCbiostats/barryr#12 is still open). LinkingTo
goes back to barry (>= 0.2.2). The formula parser regression tests exit
early when the installed barry is older than 0.2.2.9000. They run
automatically once CI installs a barry with the fix.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@gvegayon gvegayon changed the title Require barry >= 0.2.2.9000: fix td_formula covariate parsing Fix td_formula covariate parsing (tests + docs; fix via barry#26) Sep 26, 2026
@github-actions

github-actions Bot commented Sep 26, 2026 •

Copy link
Copy Markdown

Thank you for your contribution @gvegayon 🚀! The pkgdown site preview is ready for review 👉 Download here 👈!
(The artifact expires on 2026-12-25T01:42:58Z. You can re-generate it by re-running the workflow here.)

The fix is compiled into defm from barry's headers (LinkingTo), so the
installed barry version may not match what defm was built with. The tests
now try `{y0} > {y1} x Day1`, which the unfixed parser rejects, and exit
early if it fails. This works regardless of how barry is versioned.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Sep 26, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.45%. Comparing base (b016e3a) to head (62e4217).
⚠️ Report is 3 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master      #12      +/-   ##
==========================================
+ Coverage   81.37%   81.45%   +0.08%     
==========================================
  Files           8        9       +1     
  Lines         451      453       +2     
==========================================
+ Hits          367      369       +2     
  Misses         84       84              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@gvegayon
gvegayon merged commit b7bc299 into master Sep 26, 2026
13 checks passed
@gvegayon
gvegayon deleted the fix/formula-covariate-parsing branch September 26, 2026 17:57
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.

1 participant