Skip to content

Reduce mantelhaen.test() choice-argument defaults to scalars for R-devel#349

Merged
ddsjoberg merged 4 commits into
mainfrom
fix/mantelhaen-choice-arg-harvest
Jul 6, 2026
Merged

Reduce mantelhaen.test() choice-argument defaults to scalars for R-devel#349
ddsjoberg merged 4 commits into
mainfrom
fix/mantelhaen-choice-arg-harvest

Conversation

@ddsjoberg

Copy link
Copy Markdown
Collaborator

What changes are proposed in this pull request?

  • Fixed bug in ard_stats_mantelhaen_test() where multi-value choice defaults harvested from stats::mantelhaen.test() (such as the two.sided.method argument added in R-devel) were passed through unreduced, producing NULL statistics under R-devel. Choice defaults are now reduced to their default value. (Fix ard_stats_mantelhaen_test() failure on R-devel #343)

R-devel added a new argument to stats::mantelhaen.test():

mantelhaen.test(x, y, z, alternative, correct, exact, conf.level,
                two.sided.method = c("minlike", "central"))   # new in R-devel

ard_stats_mantelhaen_test() harvests all formals except the first three and previously special-cased only alternative to collapse its multi-value choice default to a scalar. The newly added two.sided.method default is an unevaluated length-2 vector, which was spliced into the mantelhaen.test() call where a single value is expected. This broke the computation so the statistic and p-value were captured as NULL, causing a test failure on R-devel (observed on win-builder for cardx 0.3.3.9001, which already includes the earlier #343 fix).

The fix generalizes the harvesting: formals with no default (symbols) are dropped, and any multi-value choice default is reduced to its default (first) element, matching match.arg() semantics. This removes the alternative-specific special case and is resilient to future signature additions.

No snapshot change is required: on release/oldrel R the assembled arguments are identical to before (alternative, correct, exact, conf.level), so the recorded ARD keeps its 8 rows. The additional two.sided.method argument exists only under R-devel, where the CRAN/win-builder checks run with snapshots skipped.

win-builder log: https://win-builder.r-project.org/GEW5mk3m5xGG/00check.log

Reference GitHub issue associated with pull request.


Pre-review Checklist (if item does not apply, mark is as complete)

  • All GitHub Action workflows pass with a ✅
  • PR branch has pulled the most recent updates from master branch: usethis::pr_merge_main()
  • If a bug was fixed, a unit test was added.
  • If a new ard_*() function was added, it passes the ARD structural checks from cards::check_ard_structure().
  • If a new ard_*() function was added, set_cli_abort_call() has been set.
  • If a new ard_*() function was added and it depends on another package (such as, broom), is_pkg_installed("broom") has been set in the function call and the following added to the roxygen comments.
  • Code coverage is suitable for any new functions/features (generally, 100% coverage for new code): devtools::test_coverage()

Reviewer Checklist (if item does not apply, mark is as complete)

  • If a bug was fixed, a unit test was added.
  • Code coverage is suitable for any new functions/features: devtools::test_coverage()

When the branch is ready to be merged:

  • Update NEWS.md with the changes from this pull request under the heading "# cardx (development version)". If there is an issue associated with the pull request, reference it in parentheses at the end update (see NEWS.md for examples).
  • All GitHub Action workflows pass with a ✅
  • Approve Pull Request
  • Merge the PR. Please use "Squash and merge" or "Rebase and merge".

R-devel added a two.sided.method = c("minlike", "central") argument to
stats::mantelhaen.test(). ard_stats_mantelhaen_test() harvests all formals
and previously only special-cased alternative, so the new multi-value
choice default was passed through unreduced. The length-2 value broke the
spliced call, causing the statistic and p-value to be captured as NULL and
the test to fail under R-devel.

Generalize the harvesting: drop no-default formals and reduce any
multi-value choice default to its first element, matching match.arg()
semantics and remaining resilient to future signature additions.

Co-authored-by: Ona <no-reply@ona.com>
@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Unit Tests Summary

  1 files  193 suites   1m 25s ⏱️
191 tests 153 ✅ 38 💤 0 ❌
705 runs  638 ✅ 67 💤 0 ❌

Results for commit 1103d4a.

♻️ This comment has been updated with latest results.

@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Unit Test Performance Difference

Additional test case details
Test Suite $Status$ Time on main $±Time$ Test Case
ard_summary.survey.design 💚 $25.08$ $-1.95$ unstratified_ard_summary.survey.design_works

Results for commit b3c9bbf

♻️ This comment has been updated with latest results.

@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

badge

Code Coverage Summary

Filename                                Stmts    Miss  Cover    Missing
------------------------------------  -------  ------  -------  -------------------------------------------
R/add_total_n.survey.design.R              10       0  100.00%
R/ard_aod_wald_test.R                      77       2  97.40%   93, 96
R/ard_attributes.survey.design.R            2       0  100.00%
R/ard_car_anova.R                          45       2  95.56%   62, 65
R/ard_car_vif.R                            68       1  98.53%   93
R/ard_categorical_ci.R                    323       1  99.69%   100
R/ard_categorical_ci.survey.design.R      124       1  99.19%   180
R/ard_continuous_ci.R                      28       1  96.43%   38
R/ard_continuous_ci.survey.design.R       138       0  100.00%
R/ard_continuous.survey.design.R          284      20  92.96%   61-66, 100, 191, 200, 351, 382-383, 434-442
R/ard_effectsize_cohens_d.R               103       2  98.06%   69, 122
R/ard_effectsize_hedges_g.R                91       2  97.80%   68, 120
R/ard_emmeans_contrast.R                   99       0  100.00%
R/ard_emmeans_emmeans.R                    97       0  100.00%
R/ard_incidence_rate.R                    104       0  100.00%
R/ard_missing.survey.design.R              89       7  92.13%   45-50, 63
R/ard_regression_basic.R                   31       1  96.77%   61
R/ard_regression.R                         87       0  100.00%
R/ard_smd_smd.R                            69       5  92.75%   57, 83-86
R/ard_stats_anova.R                        95       0  100.00%
R/ard_stats_aov.R                          46       0  100.00%
R/ard_stats_chisq_test.R                   40       1  97.50%   39
R/ard_stats_fisher_test.R                  43       1  97.67%   42
R/ard_stats_kruskal_test.R                 36       1  97.22%   38
R/ard_stats_mantelhaen_test.R              73       1  98.63%   45
R/ard_stats_mcnemar_test.R                 80       2  97.50%   63, 106
R/ard_stats_mood_test.R                    49       1  97.96%   45
R/ard_stats_oneway_test.R                  39       0  100.00%
R/ard_stats_poisson_test.R                 76       1  98.68%   59
R/ard_stats_prop_test.R                    85       1  98.82%   43
R/ard_stats_t_test_onesample.R             41       0  100.00%
R/ard_stats_t_test.R                      112       2  98.21%   65, 111
R/ard_stats_wilcox_test_onesample.R        42       0  100.00%
R/ard_stats_wilcox_test.R                  99       2  97.98%   65, 117
R/ard_survey_svychisq.R                    38       1  97.37%   44
R/ard_survey_svyranktest.R                 54       1  98.15%   44
R/ard_survey_svyttest.R                    53       1  98.11%   42
R/ard_survival_survdiff.R                  89       0  100.00%
R/ard_survival_survfit_diff.R              76       0  100.00%
R/ard_survival_survfit.R                  243       5  97.94%   234-238
R/ard_tabulate_abnormal.R                  76       0  100.00%
R/ard_tabulate_max.R                       51       7  86.27%   54-59, 74
R/ard_tabulate_value.survey.design.R       80       9  88.75%   40-45, 62, 167, 172
R/ard_tabulate.survey.design.R            407      15  96.31%   70-75, 90, 243-246, 290, 335, 535, 549
R/construction_helpers.R                  106      10  90.57%   160-175, 189, 248
R/deprecated.R                             34      34  0.00%    32-90
R/proportion_ci.R                         203       1  99.51%   463
TOTAL                                    4335     142  96.72%

Diff against main

Filename                         Stmts    Miss  Cover
-----------------------------  -------  ------  -------
R/ard_stats_mantelhaen_test.R       +4       0  +0.08%
TOTAL                               +4       0  +0.00%

Results for commit: 1103d4a

Minimum allowed coverage is 80%

♻️ This comment has been updated with latest results

@ddsjoberg
ddsjoberg enabled auto-merge (squash) July 6, 2026 16:25
@ddsjoberg
ddsjoberg merged commit 643bd46 into main Jul 6, 2026
25 checks passed
@ddsjoberg
ddsjoberg deleted the fix/mantelhaen-choice-arg-harvest branch July 6, 2026 16:29
@github-actions github-actions Bot locked and limited conversation to collaborators Jul 6, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant