Skip to content

fix: Slope selector (HL-plots) not appearing with error Error in mutate: Can't transform a data frame with NA or "" names due to underscore ("_" ) in STUDYID - #1401

Merged
Gero1999 merged 7 commits into
mainfrom
1387-bug/hl_plots-with-underscored-strings-in-key-variables
Jul 30, 2026
Merged

fix: Slope selector (HL-plots) not appearing with error Error in mutate: Can't transform a data frame with NA or "" names due to underscore ("_" ) in STUDYID#1401
Gero1999 merged 7 commits into
mainfrom
1387-bug/hl_plots-with-underscored-strings-in-key-variables

Conversation

@Gero1999

@Gero1999 Gero1999 commented Jul 17, 2026

Copy link
Copy Markdown
Collaborator

Issue

Closes #1378

Description

The Slope Selector crashed with Error in mutate: Can't transform a data frame with NA or "" names whenever a grouping value contained an underscore (e.g. STUDYID = "same_or_similar", PARAM = "Drug A").

Root cause: half-life plots are keyed by names of the form key1=val1_key2=val2_... (built in get_halflife_plots()). parse_plot_names_to_df() reversed this by splitting on every underscore, so underscores inside a value were treated as segment separators. This produced fragments with no key=, which became NA/"" column names and misaligned rows under rbind(), aborting arrange_plots_by_groups() (and therefore the plot rendering) in the NCA > Slope Selector tab.

Fix: split names only at real key= boundaries (_(?=[A-Za-z.][A-Za-z0-9.]*=), PCRE) and combine rows with bind_rows() so columns align by name. Values may now safely contain underscores or spaces. Malformed segments are dropped rather than turned into empty column names, so the crash is structurally impossible.

Definition of Done

  • Slope Selector renders plots for datasets whose STUDYID/PARAM/other grouping values contain underscores.
  • parse_plot_names_to_df() never returns NA/"" column names.
  • No regression for names without underscores in values.

How to test

  1. devtools::load_all() then aNCA::run_app().
  2. Upload a dataset with an underscore in a grouping value (e.g. STUDYID = "same_or_similar"), map it, and open NCA -> Setup -> Slope Selector.

For the dataset you can use this one:

# Generate data/Sample.csv exactly as shown

sample_df <- data.frame(
  STUDYID = c(
    rep("same_or_similar", 12),
    rep("divergent", 12)
  ),
  USUBJID = c(
    rep(S1, 12),
    rep(S2, 12)
  ),
  ATPTREF = 1,
  ROUTE = rep("intravascular bolus", 24),
  TMDD = rep("without TMDD", 24),
  Variability = rep("0.01 prop variance, 0 add variance", 24),
  AFRLT = rep(c(0, 0.5, 1, 2, 3, 4, 8, 12, 16, 24, 36, 48), 2),
  ARRLT = rep(c(0, 0.5, 1, 2, 3, 4, 8, 12, 16, 24, 36, 48), 2),
  AVAL = c(
    0.922, 0.715, 0.61, 0.405, 0.3, 0.329, 0.177, 0.091, 0.04, 0.014, 0, 0,
    1.185, 1.021, 0.71, 0.647, 0.516, 0.32, 0.109, 0.058, 0.023, 0.002, 0, 0
  ),
  DOSEA = rep(30, 24),
  DOSETRT = rep("mg", 24),
  PARAM = c(
    rep("Drug A", 12),
    rep("Drug B", 12)
  ),
  stringsAsFactors = FALSE
)

# Write CSV without row names/quotes (matches your sample style)
write.csv(sample_df, file = "../../Downloads/dataset_with_underscore_in_STUDYID.csv", row.names = FALSE)

  1. Plots render (previously: Can't transform a data frame with NA or "" names).

Covered by unit tests in tests/testthat/test-utils-slope_selector.R:

devtools::test(filter = "utils-slope_selector")

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
  • If a package dependency was added/changed, run data-raw/test_suggests_hidden.R

Notes to reviewer

  • NEWS entry not yet included in this branch. Suggested entry under a new ### Slope Selector bug-fix subsection: "Slope Selector no longer crashes with Can't transform a data frame with NA or '' names when a grouping value (e.g. STUDYID, PARAM) contains an underscore. Plot names are now parsed at key= boundaries instead of splitting on every underscore (Bug(s): 1) pak installation issue, 2) Half life plots not appearing in Slope Selector when dataset key variables contain "_" (can't transform a dataset with NA or "" in names) #1378)."
  • R was not available in the authoring environment, so devtools::test() and lintr::lint_package() were not run here. The split regex was validated against the failing inputs using the same PCRE engine (both same_or_similar and divergent parse to identical key sets, so bind_rows aligns cleanly). All changed lines are <=100 chars. Please run tests + lint before merging.
  • Version bumped 0.1.0.9184 -> 0.1.0.9185.
  • Click handling is unaffected -- it already uses structured plotly customdata, not the parsed name string.

Gero1999 added 3 commits July 17, 2026 11:39
parse_plot_names_to_df split plot names on every underscore, so grouping
values containing underscores (e.g. STUDYID = "same_or_similar") were broken
into fragments without a key. Those fragments became NA/"" column names and
misaligned rows under rbind, crashing the Slope Selector with
"Can't transform a data frame with NA or '' names".
@Gero1999 Gero1999 changed the title 1387 bug/hl plots with underscored strings in key variables Slope selector (HL-plots) not appearing with error Error in mutate: Can't transform a data frame with NA or "" names due to underscore ("_" ) in STUDYID Jul 17, 2026
@Gero1999 Gero1999 changed the title Slope selector (HL-plots) not appearing with error Error in mutate: Can't transform a data frame with NA or "" names due to underscore ("_" ) in STUDYID fix: Slope selector (HL-plots) not appearing with error Error in mutate: Can't transform a data frame with NA or "" names due to underscore ("_" ) in STUDYID Jul 17, 2026
Gero1999 added 2 commits July 17, 2026 13:23
Added details about the Slope Selector plots fix, addressing rendering errors related to grouping values with underscores.
@Gero1999
Gero1999 requested review from Shaakon35, h5hoang and vedhav July 17, 2026 11:59

@Shaakon35 Shaakon35 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

It works, even if the data is too small to allow the mean plots:

maybe we woudl need a better error in the future:

Image

@KOBANAK KOBANAK left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I tested with another dataset with "_" in STUDYID and it works as expected.
We no longer see the previous error in the slope selector section.

@Gero1999
Gero1999 merged commit d226c35 into main Jul 30, 2026
13 checks passed
@Gero1999
Gero1999 deleted the 1387-bug/hl_plots-with-underscored-strings-in-key-variables branch July 30, 2026 12:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants