Add km_by_hand_table() and na_by_hand_table() functions#899
Conversation
Port the Kaplan-Meier and Nelson-Aalen by-hand table builders from ucdavis/epi204 (PR #272) into rme as exported package functions. - km_by_hand_table(): step-by-step KM table (S_prev x factor = S_new) - na_by_hand_table(): Nelson-Aalen table (H_prev + d/n = H_new, exp(-H)) Both return knitr_kable objects of LaTeX math strings. Move dplyr into Imports and add utils (both used by the new functions). https://claude.ai/code/session_011MedxXwDfmV4GnQVDDgzGv
|
Claude finished @d-morrison's task in 3m 9s —— View job Code Review
The overall structure is clean and the fraction-arithmetic approach is clever. A few correctness issues and one portability concern are worth fixing before this is wired into a chapter. Bug — Non-integer
|
|
Claude finished @d-morrison's task in 2m 44s —— View job Code Review
The structure is clean and the fraction-tracking approach is pedagogically sound. The previous automated review (06:35 UTC) already identified the main issues; I've independently verified all of them and found two additional items. Bug —
|
|
Claude finished @d-morrison's task in 3m 49s —— View job Code Review
The structure is sound and the fraction-arithmetic approach works well for pedagogy. Two earlier automated reviews (06:35 and 07:06 UTC) found the major issues; I've independently verified all of them and found one additional item. Findings are grouped below; the five bugs are the blockers. Bugs
|
…h; add examples - Time-point columns initialised as numeric() not integer() (preserve non-integer times) - Replace format() with fixed-point formatC() in math strings (avoid LaTeX-breaking scientific notation near zero) - Track running fraction numerators/denominators as doubles (avoid 32-bit integer overflow) - Validate death is 0/1 or logical - Add runnable @examples to both functions - Document na_by_hand_table()'s \expf macro dependency in @details https://claude.ai/code/session_011MedxXwDfmV4GnQVDDgzGv
|
Claude finished @d-morrison's task in 3m 36s —— View job Code Review
Good follow-through on the prior round of reviews. All five bugs called out in the 07:47 run have been correctly fixed; my independent verification of each is below, followed by one item that was raised but not addressed. Fixes verified as correct
Integer overflow —
One unaddressed itemMissing NA check for the
|
|
Thanks for the reviews. Addressed in 1259e7a:
One suggestion not taken — extracting These functions were ported from Generated by Claude Code |
|
Claude finished @d-morrison's task in 3m 16s —— View job Code Review
All five bugs called out in the prior review cycle ( Missing NA guard for
|
Built to branch |
|
@claude review (Verifying the dispatch-permission fix merged in #911 — this should now fire a dispatched Generated by Claude Code |
|
👀 Picked up by workflow run #27715975209. R/Quarto/renv setup runs first (~3-5 min); Claude itself responds after that. |
|
Claude finished @d-morrison's task in 2m 47s —— View job Code Review
Good state post-fixes. All five bugs from the earlier review cycle are correctly resolved. Three items remain — one medium carry-over that has now appeared in three consecutive automated reviews without being addressed, and two low-priority formatting consistency issues. Carry-over — Missing NA guard for
|
…nators
- Add stopifnot guard rejecting NA in 'time' (NA rows sort last but still
count toward n, inflating the risk set)
- Format double-valued running numerators/denominators with %.0f instead of
%d (avoids coercion warnings under options(warn=1) and float-rounding
truncation); keep %d for the genuine-integer di/ni
- Replace as.character(cum_haz_n) with sprintf("%.0f", ...) to avoid
scientific notation for large integer hazard numerators
https://claude.ai/code/session_011MedxXwDfmV4GnQVDDgzGv
… into claude/admiring-dijkstra-ithzii
|
All three addressed in the latest push (45f304a):
Generated by Claude Code |
|
Claude finished @d-morrison's task in 3m 21s —— View job Code Review
All nine issues flagged across the prior review cycle are correctly addressed. Independent verification below. All prior findings resolved ✓
The The No new findingsThe logic is sound end-to-end:
DESCRIPTION / NAMESPACE — correct
Noted design decision (not a finding)
This PR is ready from a code-correctness standpoint. |
Ports the Kaplan-Meier and Nelson-Aalen "by-hand" table builders from
ucdavis/epi204PR #272 intormeas exported package functions.Previously
rmehad no equivalent: it computed KM by hand inline in_subfiles/intro-to-survival-analysis/_sec-surv-KM-calculations.qmd(adplyrworksheet printed withpander), and had no by-hand Nelson-Aalen table at all.Changes
R/km_by_hand_table.R—km_by_hand_table(data): step-by-step KM table, each event row shown asS_prev × factor = S_new.R/na_by_hand_table.R—na_by_hand_table(data): Nelson-Aalen table showingH_prev + d/n = H_newand survivalexp(-H)(uses the\expfmacro already defined inrme).timeanddeathcolumns and return aknitr_kableof LaTeX math strings (escape = FALSE).NAMESPACE+man/*.Rd: export and document both functions.DESCRIPTION: movedplyrfrom Suggests to Imports and addutils(both used by the new functions).Verification
lintr::lint()on both new files — no lints.spelling::spell_check_package()— no spelling errors.No
.qmd/subfiles were edited, so no chapter render was required. The functions are not yet wired into any chapter — happy to add usage to the survival subfiles in a follow-up if desired.https://claude.ai/code/session_011MedxXwDfmV4GnQVDDgzGv
Generated by Claude Code