Add get_surv_times_df and get_surv_diff_df()/ overhaul creation of survival times tables #269
Add get_surv_times_df and get_surv_diff_df()/ overhaul creation of survival times tables #269jszczypinski wants to merge 18 commits into
Conversation
**What changes are proposed in this pull request?** * `tbl_survfit_quantiles()` now indicates censored observation in min/max values with `*` (#192) Small change as requested in the issue below: Censored min/max range values are now marked with `*` Closes #192 -------------------------------------------------------------------------------- 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. - [ ] Code coverage is suitable for any new functions/features (generally, 100% coverage for new code): `devtools::test_coverage()` - [ ] Request a reviewer Reviewer Checklist (if item does not apply, mark is as complete) - [ ] If a bug was fixed, a unit test was added. - [ ] Run `pkgdown::build_site()`. Check the R console for errors, and review the rendered website. - [ ] 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 "`# cards (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".
This reverts commit b610804.
This reverts commit 382610f.
Unit Tests Summary 1 files 263 suites 3m 54s ⏱️ Results for commit 0fc082a. ♻️ This comment has been updated with latest results. |
Unit Test Performance Difference
Additional test case details
Results for commit b726237 ♻️ This comment has been updated with latest results. |
Code Coverage SummaryDiff against mainResults for commit: 0fc082a Minimum allowed coverage is ♻️ This comment has been updated with latest results |
| get_surv_times_df <- function(fit_km, times, conf_int = 0.95, scale = 1) { | ||
| # Enforce rigorous type-checking using rlang | ||
| if (!inherits(fit_km, "survfit")) { | ||
| rlang::abort("`fit_km` must be a survfit object.") |
There was a problem hiding this comment.
I like it a lot!!! I think it is an amazing way forwards. Just wondering if the two get_* could be in the tbl_survfit_times. Just wondering because if they are only used there that would make documentation a bit more compact and direct (I know I have asked differently for helper functions in the past but these are exported and used only there right?)
There was a problem hiding this comment.
I will do the full review tomorrow! ;)
This PR overhauls the survival time summary pipeline, shifting from a tightly coupled architecture to a modular two-step process (Data Extraction ➔ Presentation). This mirrors tbl_coxph() and empowers users to manipulate summary contents via standard dplyr wrangling before rendering tables or plotting annotations.
🚀 New Extraction Engine
get_surv_times_df(): A new function to extract survival metrics, numbers at risk, and CIs into a highly malleable data.frame.
get_surv_diff_df(): Added a companion extractor leveraging cardx to calculate pairwise survival differences, complete with CIs and p-values.
🎨 Presentation & Rendering
tbl_survfit_times(): Refactored to process structured data frames rather than raw survfit models. Automatically maps dynamically bound columns (like the p-value output from get_surv_diff_df()).
annotate_surv_med(): Updated the function signature to accept a pre-computed data frame (surv_tbl), acting as a generic floating table renderer identical to annotate_coxph().
🛑 Legacy Migration & Fixes
Defunct Methods: Made add_overall() and add_difference_row() defunct for tbl_survfit_times. They now throw explicit errors guiding users to extract data and use the dplyr::bind_rows() workflow instead.
Strict Type Safety: Resolved vctrs/bind_rows() crashes by ensuring empty columns map correctly to NA_real_ across extractors.
Documentation Clean-up: Fixed Roxygen2 parameter mismatches and rewrote @examples to demonstrate advanced configuration scenarios.
Closes #268
Pre-review Checklist (if item does not apply, mark is as complete)
usethis::pr_merge_main()devtools::test_coverage()Reviewer Checklist (if item does not apply, mark is as complete)
pkgdown::build_site(). Check the R console for errors, and review the rendered website.devtools::test_coverage()When the branch is ready to be merged:
NEWS.mdwith the changes from this pull request under the heading "# cards (development version)". If there is an issue associated with the pull request, reference it in parentheses at the end update (seeNEWS.mdfor examples).