Skip to content

Change risk table order #213#260

Closed
ShreyaSreeram27 wants to merge 7 commits intomainfrom
change-risk-table-order-#213
Closed

Change risk table order #213#260
ShreyaSreeram27 wants to merge 7 commits intomainfrom
change-risk-table-order-#213

Conversation

@ShreyaSreeram27
Copy link
Copy Markdown
Collaborator

@ShreyaSreeram27 ShreyaSreeram27 commented Sep 1, 2025

What changes are proposed in this pull request?

  • Changing risk table order to follow factor levels
  • Applying fix to tidy_survfit() and tidy_cuminc()

If there is an GitHub issue associated with this pull request, please provide link.

Closes #213

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

  • Ensure all package dependencies are installed by running renv::install()
  • PR branch has pulled the most recent updates from master branch. Ensure the pull request branch and your local version match and both have the latest updates from the master branch.
  • If a new function was added, function included in _pkgdown.yml
  • If a bug was fixed, a unit test was added for the bug check
  • Run pkgdown::build_site(). Check the R console for errors, and review the rendered website.
  • Overall code coverage remains >99.5%. Review coverage with withr::with_envvar(list(CI = TRUE), code = devtools::test_coverage()). Begin in a fresh R session without any packages loaded.
  • R CMD Check runs without errors, warnings, and notes
  • usethis::use_spell_check() runs with no spelling errors in documentation

When the branch is ready to be merged into master:

  • Update NEWS.md with the changes from this pull request under the heading "# ggsurvfit (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).
  • Increment the version number using usethis::use_version(which = "dev")
  • Run usethis::use_spell_check() again
  • Approve Pull Request
  • Merge the PR. Please use "Squash and merge".

@ShreyaSreeram27
Copy link
Copy Markdown
Collaborator Author

ShreyaSreeram27 commented Sep 2, 2025

Hi @ddsjoberg i just wanted to summarise my changes for this PR here:

The original problematic line of code in .construct_Strata_labels:

x$strata <- factor(x$strata, levels = unique(x$strata))

I attempted to add in logic to

  • extract original factor levels from source data
  • match current strata values to original factor structure
  • reconstruct factors with preserved ordering
  • handle edge cases with robust fallbacks
    for both survival and competing risk models(because both cuminc() and survfit() use .construct_strata_labels()). The updates also generated new snapshots that reflect this new risk table ordering which should now be grouped by that factor first (in the example snapshots it is sex). The curves and values all remain the same.

let me know if this is looking good!

PS: This will also cause the snapshots from other test files to fail, but I wanted to first get the logic and function approved before committing all of them! only the testtidy_Survfit snapshots have been committed now!

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.

Change risk table order

1 participant