Fix extract_strata() stripping parentheses from strata level labels#338
Merged
Conversation
Contributor
Unit Tests Summary 1 files 193 suites 1m 23s ⏱️ Results for commit b8b121b. ♻️ This comment has been updated with latest results. |
Contributor
Unit Test Performance DifferenceAdditional test case details
Results for commit bd51179 ♻️ This comment has been updated with latest results. |
The greedy regex gsub('.*\\(', ...) in extract_strata() was intended
to strip strata() wrappers but also destroyed parentheses in factor
level values, e.g. 'Drug (B)' became 'B'.
Replace with targeted patterns that only strip the strata() wrapper.
Fixes ddsjoberg/gtsummary#2388
Co-authored-by: Ona <no-reply@ona.com>
71ee5ed to
bdbf89a
Compare
Contributor
Code Coverage SummaryDiff against mainResults for commit: b8b121b Minimum allowed coverage is ♻️ This comment has been updated with latest results |
Collaborator
Author
|
@Melkiades can you review this PR? |
Melkiades
reviewed
Apr 29, 2026
Melkiades
reviewed
Apr 29, 2026
Melkiades
approved these changes
Apr 29, 2026
Contributor
Melkiades
left a comment
There was a problem hiding this comment.
Looks very good to me! The new regex works perfectly. Thanks @ddsjoberg !!
Collaborator
Author
|
Thank you for the review @Melkiades !! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes the greedy regex in
extract_strata()that destroyed parentheses in factor level values. For example, a strata level"Drug (B)"was truncated to"B".Closes ddsjoberg/gtsummary#2388
Changes
The two
gsub(".*\\(", "", gsub("\\)", "", ...))calls were intended to stripstrata()wrappers from term labels and strata strings, but they also removed all parentheses from level values. Replaced with targeted patterns:sub("^strata\\(\\s*([^,)]+).*\\)$", "\\1", x_terms)— only matches thestrata(...)wrappergsub("strata\\(([^)]+)\\)", "\\1", i)— only replacesstrata(varname)withvarnameTesting
Added a test case with parentheses in level labels (
"Male (M)","Female (F)"). Verified no regressions with normal levels,=in levels, unstratified models, multiple stratification variables, and quantile mode.