Bug fix: prevent PKNCA_impute_method_FALSE error from YAML impute_c0 uploaded issue #1266#1322
Conversation
pharmaverse#1266) When start_impute=FALSE, create_start_impute() is skipped and data$intervals has no impute column. dplyr mutate falls back to the function parameter impute=FALSE, producing "blq, FALSE" which PKNCA interprets as an imputation method name lookup for the non-existent PKNCA_impute_method_FALSE. Fix: initialize the impute column before BLQ imputation is applied, matching the existing guard pattern in rm_impute_obs_params(). Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
…CLAUDE.md Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Shaakon35
left a comment
There was a problem hiding this comment.
Thank you for the fix,
I still have an issue with this settings:
ERROR [2026-05-27 10:28:52] Error calculating NCA results:
Can't join x$AGE with y$AGE due to incompatible types.
ℹ x$AGE is a .
ℹ y$AGE is a .
also, somehow the nca is not re-run automatically (maybe because of the bug of the AGE), let's see when that is fixed.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
…rmaverse#1266) Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
…e#1266) When settings YAML contains group columns like AGE in RefGroups (e.g. "AGE: 25"), the parsed values are character strings. Joining these with PKNCA result data (where AGE is numeric) triggers dplyr's strict type check: "Can't join due to incompatible types". Two fixes: 1. ratio_calculations.R: Add .coerce_group_types() to convert YAML character values to match the corresponding column types in data before merge() and anti_join() operations. 2. PKNCA.R: Restrict remove_pp_not_requested() group_by to only PKNCA-essential columns, excluding user keep_interval_cols (like AGE) that are irrelevant for parameter-request matching. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
|
Thanks for your review. Upon further analysis, the issues below were confirmed and resolved, About the AGE incompatible types error: The root cause was in the ratio calculation pipeline. When the settings YAML specifies group columns like The fix adds a Additionally, About NCA not re-running automatically: This was a consequence of the AGE error — the join failure aborted the auto-replay flow before NCA could complete. With the type coercion fix, auto-replay should now work correctly. I've verified locally that uploading the same dataset + settings YAML now succeeds with SUCCESS: NCA results calculated. Note: In my testing, the settings YAML specifies |
|
Thanks, now no crash but there is an issue with the AUCINT, it's complelty buggy, let me investigate :/ |
- slope_selector.R: use reset_reactable_memory() instead of inline JS - settings.R: add missing reset_reactable_memory() in .restore_non_filter_settings to prevent stale reactable.extras widget values on settings upload Co-authored-by: Ona <no-reply@ona.com>
|
The original crash from #1266 (
Both are pre-existing issues not introduced by this PR. |
Shaakon35
left a comment
There was a problem hiding this comment.
Thanks for fixing this, very helpful!
Co-authored-by: Ona <no-reply@ona.com>
Co-authored-by: Ona <no-reply@ona.com>
Co-authored-by: Ona <no-reply@ona.com>
Co-authored-by: Ona <no-reply@ona.com>
|
|
|
The One request:
The |
wangzhengdna-lang
left a comment
There was a problem hiding this comment.
@Shaakon35 Added 4 unit tests for .coerce_group_types() covering all requested cases:
- Character → numeric (AGE "25" coerced to double)
- Character → factor with correct levels (RACE "WHITE" matched to factor levels)
- Already-matching types unchanged (numeric stays numeric, character stays character)
- Mixed columns (AGE coerced, RACE/SEX unchanged)
All 151 ratio tests pass.
|
@h5hoang Could you please have a review? :) |
Issue
Closes #1266
Description
Uploading a settings YAML with
impute_c0: no(e.g.,All_settings_changed.yamlattached to the issue) causes NCA to fail with:Root cause
impute_c0: noin YAML parses to R logicalFALSE. This flows toupdate_main_intervals(impute = FALSE), which skipscreate_start_impute(). Sincecreate_start_impute()is responsible for adding theimputecolumn todata$intervals, the column never exists.When BLQ imputation is subsequently applied via
dplyr::mutate(impute = ifelse(is.na(impute) | impute == "", "blq", paste0("blq, ", impute))), dplyr cannot find animputecolumn in the data frame and falls back to the function parameterimpute = FALSEfrom the calling environment. This producespaste0("blq, ", FALSE)→"blq, FALSE". PKNCA'sPKNCA_impute_fun_list()splits this by comma, finds"FALSE", and attempts to locate the non-existent functionPKNCA_impute_method_FALSE.Fix
One-line guard in
update_main_intervals()(intervals.R:292-298) — initialize theimputecolumn before the BLQ code block, identical to the existing guard already present inrm_impute_obs_params()(same file, line 341):Definition of Done
impute_c0: nono longer causesPKNCA_impute_method_FALSEerrorimpute_c0: yesstill works correctly (no regression)impute_c0 = FALSEworks correctly (impute column gets"blq"only)rm_impute_obs_params()How to test
devtools::load_all()All_settings_changed.yamlfrom the issue Bug: error in `PKNCA_impute_fun_list() #1266 , run NCA — should complete without thePKNCA_impute_method_FALSEerrorContributor checklist
.scsschange was done, rundata-raw/compile_css.R— N/Adata-raw/test_suggests_hidden.R— N/ANotes to reviewer
if (!"impute" %in% names(...))) that mirrors an identical pattern inrm_impute_obs_params()(same file, 20 lines below). No new patterns introduced.imputefunction parameter and a data frame column. A follow-up could rename the parameter tostart_imputeto avoid this class of bug entirely, but that would touch more call sites and is out of scope for this minimal fix.issue#1266/All_settings_changed.yamlfile attached to the issue was used to confirm the root cause but is not included in this commit.