Skip to content

fix: handle all-NA PPSTRESU groups in descriptive statistics#1217

Open
Gero1999 wants to merge 18 commits intomainfrom
1216-bug/modeunit-null-crash
Open

fix: handle all-NA PPSTRESU groups in descriptive statistics#1217
Gero1999 wants to merge 18 commits intomainfrom
1216-bug/modeunit-null-crash

Conversation

@Gero1999
Copy link
Copy Markdown
Collaborator

@Gero1999 Gero1999 commented Apr 10, 2026

Issue

Closes #1216

Description

When PPSTRESU is NA for all rows in a parameter group (common with partial AUC intervals like RCAMINT where no result was computed), two things break:

  1. Descriptive statistics crashtable(PPSTRESU) drops NAs, returning an empty table. names(sort(empty_table, ...)[1])[1] returns NULL, which dplyr::mutate can't combine with character results from other groups.

  2. Column names get NA suffixifelse(PPSTRESU != "", ...) returns NA when PPSTRESU is NA, producing names like RCAMINT_0-20NA.

Fixes:

  • Extract .mode_unit() helper in calculate_summary_stats.R that returns NA_character_ for empty/all-NA input
  • Guard PPTESTCD formatting against NA ModeUnit
  • Add !is.na(PPSTRESU) guard to all ifelse(PPSTRESU != "", ...) patterns in pivot_wider_pknca_results.R (4 locations) and label_operators.R (2 locations)

Definition of Done

  • calculate_summary_stats() no longer crashes with all-NA unit groups
  • Manual interval parameters appear as RCAMINT_0-20 (not RCAMINT_0-20NA)
  • Parameters with no units appear without a unit suffix in the output
  • Existing behavior unchanged for groups with valid units

How to test

  1. Upload a dataset with both SERUM and URINE specimens
  2. In NCA settings, add partial AUC intervals (AUCINT and RCAMINT)
  3. Run NCA computation
  4. In NCA Results > Select Parameters — verify RCAMINT appears as RCAMINT_0-20 (no NA suffix)
  5. Navigate to Descriptive Statistics — should render without error
  6. Verify that RCAMINT columns appear without unit brackets, while other parameters retain their units

Contributor checklist

  • Code passes lintr checks
  • Code passes all unit tests
  • New logic covered by unit tests
  • New logic is documented
  • App or package changes are reflected in NEWS
  • Package version is incremented
  • R script works with the new implementation (if applicable)
  • Settings upload works with the new implementation (if applicable)
  • If any .scss change was done, run data-raw/compile_css.R

Notes to reviewer

First reported in #1169 (review). The root cause is that export_cdisc.R correctly sets PPSTRESU = NA when PPSTRES is NA (CDISC SD0027), but downstream code assumed PPSTRESU is always a non-NA string. The fix adds NA guards at all 7 affected locations across 3 files."

Gero1999 and others added 3 commits April 10, 2026 06:59
table() without useNA drops NA values, returning an empty table when
all PPSTRESU values are NA. names(sort(empty_table, ...)[1])[1] then
returns NULL, which dplyr::mutate cannot combine with character results
from other groups.

Extract .mode_unit() helper that returns NA_character_ for empty tables.
Also guard the downstream PPTESTCD formatting against NA ModeUnit.

Closes #1216

Co-authored-by: Ona <no-reply@ona.com>
- Test calculate_summary_stats with a mix of normal and all-NA unit
  groups (CMAX + RCAMINT scenario from the bug report)
- Test .mode_unit edge cases: all-NA, empty vector, mixed NA/values

Co-authored-by: Ona <no-reply@ona.com>
Co-authored-by: Ona <no-reply@ona.com>
@Gero1999 Gero1999 requested review from Shaakon35 and js3110 April 10, 2026 08:38
@Gero1999 Gero1999 marked this pull request as ready for review April 10, 2026 08:38
Gero1999 and others added 9 commits April 10, 2026 08:44
The helper was inserted between the roxygen docs and the function
definition, which would cause devtools::document() to detach the
docs from calculate_summary_stats. Moving .mode_unit (with @nord)
to the top of the file keeps both roxygen blocks correctly associated.

Co-authored-by: Ona <no-reply@ona.com>
@Shaakon35
Copy link
Copy Markdown
Collaborator

Shaakon35 commented Apr 10, 2026

image

RCAMINT does not appear.

Also can you fix the typo in tab_nca.R:

msg <- paste0(

"Urine Parameters (FREXINT, RCAMINT) calculated for non-urine samples",
"will return NA values and units"

-> use paste to add a " "

@Gero1999
Copy link
Copy Markdown
Collaborator Author

@Shaakon35 did you include Urine in the NCA setup?

Copy link
Copy Markdown
Collaborator

@js3110 js3110 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Shaakon35
Copy link
Copy Markdown
Collaborator

Shaakon35 commented Apr 10, 2026

I tried again, added Plasma and Urine.

Descriptive stats:
image

NCA results:
RCAMINT is there two times, but I asked it only once:
image

Can you fix that please? :)
Except if that is correct? but I doubt

@Gero1999 Gero1999 marked this pull request as draft April 13, 2026 12:06
Gero1999 and others added 5 commits April 13, 2026 12:06
When PPSTRESU is NA (e.g., RCAMINT with no computed result),
ifelse(PPSTRESU != "", ...) returns NA, producing column names
like RCAMINT_0-20NA. Add !is.na(PPSTRESU) guard in all 4 locations:
main interval PPTESTCD, manual interval_name (vals + exclude),
and add_label_attribute.

Co-authored-by: Ona <no-reply@ona.com>
Same NA PPSTRESU fix as pivot_wider_pknca_results — the exported
add_label_attribute has the identical case_when pattern.

Co-authored-by: Ona <no-reply@ona.com>
Verify that pivot_wider_pknca_results and add_label_attribute produce
clean column names (e.g., RCAMINT_0-20) instead of NA-suffixed ones
(RCAMINT_0-20NA) when PPSTRESU is NA.

Co-authored-by: Ona <no-reply@ona.com>
The test was injecting rows with mismatched start/end vs start_dose/
end_dose, causing add_label_attribute to produce a different number
of mapped columns than the pivot. Use a template row and compute
consistent absolute times from dose_time.

Co-authored-by: Ona <no-reply@ona.com>
@Gero1999
Copy link
Copy Markdown
Collaborator Author

hey @Shaakon35, it is "correct". The problem is that right now when you request an interval parameter you do it for all PCSPEC (SERUM, URINE) even if you request urine interval parameters (i.e, RCAMINT). Therefore, the results show two columns, one for the URINE, which has the expected units, and one for the SERUM, which is not possible to calculate and has NA units.

I changed it so now the NA units show in a clean way:

image

However, notice that this is merely aesthetic. Let me know if you think something else should be done

@Gero1999 Gero1999 marked this pull request as ready for review April 14, 2026 12:53
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.

Bug: Descriptive statistics crash when PPSTRESU is all NA for a parameter group

3 participants