Refactoring with checkmate and rlang - #548
Conversation
|
This looks like it will make all of the code more consistent. Thank you!. Please merge in the current origin/main branch and resolve the conflicts. Also, for many of the checkmate calls, you've added |
…ng-refactor # Conflicts: # R/001-add.interval.col.R # R/PKNCA.options.R # R/assertions.R # R/auc.R # R/aucint.R # R/class-PKNCAdata.R # R/class-PKNCAdose.R # R/class-general.R # R/class-summary_PKNCAresults.R # R/exclude.R # R/interpolate.conc.R # R/pk.calc.all.R # R/pk.calc.c0.R # R/superposition.R # R/tss.R # R/tss.monoexponential.R # R/tss.stepwise.linear.R # tests/testthat/test-PKNCA.options.R
|
Here are the comprehensive findings: Additional review findingsThese supplement the 6 inline comments already on the diff (non-unique classes, Severity token missing from some preexisting condition classes — breaks class-based captureThree internal "report a bug" errors are raised with a
Their siblings correctly use Negative-path tests deleted instead of migrated — coverage regressionPlease restore the tests to match the previous intent. Across ~10 test files, the
The new behavior is now less tested than the old. Please convert these to checkmate semantics quietly differ from the manual checks they replacedPlease add tests for where these tests are stricter: CI can't catch these because the negative tests (finding 2) were deleted. All verified against base:
None look dangerous, but they're undocumented behavior changes with no test pinning them. Please find remaining stop and warning calls"Replaced all
|
…ng-refactor Conflicts: NEWS.md R/001-add.interval.col.R R/aucint.R R/pk.calc.all.R R/pk.calc.urine.R tests/testthat/test-001-add.interval.col.R
Conflicts: NEWS.md
NEWS.md: - Restore the deleted changelog entry for the unsorted concentration-time fix, which a merge dropped while leaving its code and test in place. - Split two bullets that a merge glued together, and put the "Bug Fixes" heading back on its own line so the section renders. - Remove the pk_nca_result_to_df() entry: that regression was introduced and fixed within this branch, so no released version exhibited it. - Document the pknca_* condition class renames under Breaking changes, including the two sparse classes merged into one. Revert the new S3method(AIC,list) registration. AIC.list() keeps @nord, so AIC() dispatch on lists is unchanged from main. Restore the base formatting of aucint.R, pk.calc.c0.R, time.above.R, and AIC.list.R, keeping only the condition-signaling changes. These four were reindented wholesale, which inflated the diff without changing behavior: aucint.R alone was 991 changed lines carrying 22 real ones. The branch diff drops from 4760 changed lines to 3184; the test suite is unchanged at 2745 passing. Co-Authored-By: Claude Opus 5 <[email protected]>
Expanding one-line stop() calls into multi-line rlang::abort() calls left `# nocov` on only some lines of each call, so the unmarked middle lines still counted toward coverage. Per the contributing guide, regions of three or more lines are bracketed with `# nocov start` / `# nocov end`; statements of one or two lines keep a trailing marker on each line. 35 sites across 14 files. Every converted region contains exactly one rlang::abort() or rlang::warn() call and nothing else. Also bracket the closure in zero_len_summary(), where a pre-existing pair of bare `#nocov` markers on the first and last line left the nine-line body counted. Co-Authored-By: Claude Opus 5 <[email protected]>
…isc_arg The class names were built with sprintf() from the argument name, so the six resulting classes could not be grepped for and only the three pptestcd_cdisc ones were ever evaluated -- a typo in the pptest_cdisc trio would have gone unnoticed. Three literal classes cover both arguments and are exercised by the existing tests. Replace the hand-rolled scalar and name checks with checkmate::test_string() and checkmate::test_names(), keeping rlang::abort() so each failure retains its class. Drop the redundant length(x) != 1 test, which identical(names(x), "route") already implies. Document the validation itself in NEWS: it is stricter than the previous character-or-list check and can reject input that add.interval.col() used to accept. Co-Authored-By: Claude Opus 5 <[email protected]>
Condition signaling:
- Drop the named `message =` argument from every rlang::abort/warn/inform
call (301 sites); it is distinctly the first argument.
- Condense 108 short calls onto one line so `# nocov` can be a trailing
marker rather than a start/end bracket.
- Give every condition class a distinct value (17 sites across 10 reused
names), so callers such as ANCA or ruminate can capture a specific
failure rather than a shared one.
- Replace paste()/paste0() message assembly with sprintf templates (20
sites) so the message a user reports can be grepped for in the source,
and hoist the branching message in choose_interval_method() out of the
abort call.
checkmate:
- assert_unit_col() uses assert_names(must.include=) and
assert_character() in place of two hand-rolled classed aborts.
- add.interval.col() uses assert_list(names = "unique"); the empty-list
conditional was dead because checkmate accepts a zero-length list.
- choose_interval_method() folds the conc/time length check into the
time assertion via len = length(conc).
- pk_nca_result_to_df() reads warning_prep$message directly rather than
through conditionMessage().
Formatting, limited to lines this PR introduced:
- Restore `) {`, drop trailing whitespace, and put closing braces on
their own line (80 lines). Lines unchanged from the base are untouched.
- Remove the leftover `info` arguments from test-001-add.interval.col.R.
Tests follow the renamed classes: the Tobit half-life cases now pin
pknca_warning_halflife_too_few_points_tobit, and the assert_unit_col
cases pin checkmate's messages.
Co-Authored-By: Claude Opus 5 <[email protected]>
Extends the earlier pass, which only recognized a call whose message was a string literal. A message that is a variable or a nested sprintf() is now flattened too, which is what left calls such as rlang::abort(unit_col, class = ...) spread over four lines. A call inside a `# nocov start` / `# nocov end` bracket is allowed a longer line, since collapsing it also removes the two marker lines and leaves a trailing `# nocov`; the limit is 175 characters there and 120 elsewhere. 44 calls collapsed and nocov brackets drop from 42 to 12. Whitespace is only collapsed outside string literals, so no message text changes. The 12 remaining brackets are not single calls (.onLoad, the lifecycle shims, a closure), wrap two statements, or would exceed 180 characters on one line. Co-Authored-By: Claude Opus 5 <[email protected]>
No description provided.