Skip to content

Share the argument handling between ssd_hc() and ssd_hp() - #203

Draft
joethorley wants to merge 1 commit into
devfrom
joethorley/hcp-validation
Draft

joethorley wants to merge 1 commit into
devfrom
joethorley/hcp-validation

Conversation

@joethorley

Copy link
Copy Markdown
Member

Summary

ssd_hc.fitdists() and ssd_hp.fitdists() shared 44 of their 70 to 80 body lines: the same multi_est and ci_method = "weighted_arithmetic" deprecation blocks and the same chk_*() sequences, then a call to hcp(). The ssd_hp(proportion = FALSE) soft deprecation appeared verbatim three times (ssd_hp.fitdists(), ssd_hp.fitburrlioz(), ssd_hp_bcanz()). The computation was already unified in the hcp* family; this PR unifies the argument handling too, in three internal helpers beside .hc_proportion() in R/hc.R:

  • .hcp_est_method(est_method, multi_est, fun)
  • .hcp_ci_method(ci_method, fun)
  • .hp_proportion(proportion, deprecated, fun, id = NULL)

fun names the calling function in the messages, so the text is unchanged per call site. Each argument's validation and deprecation now lives in one place, which makes the escalations planned in #198 a single change each.

The one non-obvious part

lifecycle::deprecate_soft() only warns when the deprecated function was called from the global environment or from a test, and it determines that from its calling frames (env and user_env). Moving the call into a helper made the helper the "deprecated function", whose caller is package code, and every soft deprecation went silent. lifecycle::expect_deprecated() did not notice because it forces lifecycle_verbosity = "warning", so the full suite stayed green through the broken intermediate state. The helpers therefore pass env = parent.frame() and user_env = parent.frame(2), the exported function's frame and its caller's frame, and a new test under lifecycle_verbosity = "warning" exercises all five deprecation paths so a future move cannot silence them again.

Verification

Deprecation output for six calls (ssd_hp(f, 1), ssd_hp_bcanz(f, 1), ssd_hc(f, multi_est = TRUE), ssd_hp(f, 1, multi_est = FALSE), and ci_method = "weighted_arithmetic" through both ssd_hc() and ssd_hp()) is byte identical between dev and this branch. No snapshot changed. Full suite 1408 passing, 0 failures; R CMD check 0 errors, 0 warnings, 0 notes; air format --check clean.

Also adds a test that ssd_hp() rejects an unknown est_method or ci_method with the same chk_subset() message as ssd_hc(); hcp() already did this internally, so it passed before and after, but it now documents the contract at the front door.

`ssd_hc.fitdists()` and `ssd_hp.fitdists()` repeated the same
`multi_est` and `ci_method = "weighted_arithmetic"` deprecation blocks
and `chk_*()` sequences, and the `ssd_hp(proportion = FALSE)` soft
deprecation appeared verbatim in `ssd_hp.fitdists()`,
`ssd_hp.fitburrlioz()` and `ssd_hp_bcanz()`. Move them into three
helpers next to `.hc_proportion()`, so each argument's validation and
deprecation lives in one place and the escalations planned in #198 are
a single change each.

`lifecycle::deprecate_soft()` only warns when the deprecated function
was called from the global environment or a test, and works that out
from its calling frames, so the helpers pass the exported function's
frame and its caller's frame explicitly. Without that the warnings
vanished while `lifecycle::expect_deprecated()`, which forces
verbosity, still passed; a test under `lifecycle_verbosity = "warning"`
now guards it. The messages are byte identical to `dev` for all six
deprecation paths.

No snapshot changes.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

This branch has not been deployed

No deployments
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