Extend get_required_input_variables: Pharmpy object, data arg, bug fixes#47
Extend get_required_input_variables: Pharmpy object, data arg, bug fixes#47roninsightrx merged 6 commits intomainfrom
Conversation
- Accept Pharmpy NONMEM model object in addition to file path and code string - Add `data` argument (data.frame or CSV path) to populate data_col from actual dataset column names via positional matching - Auto-detect dataset from $DATA record when no data argument supplied; warn clearly when the file cannot be found - Relax column-count check: trim extra trailing data columns instead of aborting, warn only when data has fewer columns than $INPUT entries - Fix .parse_nm_input: NONMEM rename syntax is NONMEM_NAME=DATA_COL (was reversed); remove data_col from parser since it is now set by caller - Add comprehensive test suite covering all classification types, data resolution paths, edge cases, and error conditions Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Adds a new exported helper for parsing NONMEM $INPUT and determining which input variables are required for simulation, with optional dataset-based resolution of data_col and expanded input types (model string/path/Pharmpy object).
Changes:
- Introduces
get_required_input_variables()with internal helpers to parse$INPUT, detect dose-timing RHS variables, and optionally resolvedata_colviadataor$DATA. - Adds comprehensive test coverage for classification, renames/DROP, IGNORE=C, multiline/inline-comment
$INPUT, and data resolution behavior. - Adds roxygen2 docs/man pages, exports the new API, and bumps package version.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| R/get_required_input_variables.R | New exported function + internal parsing/data-resolution helpers |
| tests/testthat/test-get_required_input_variables.R | New tests covering parsing, classification, and data resolution paths |
| man/get_required_input_variables.Rd | Public API documentation |
| man/dot-resolve_data_cols.Rd | Internal helper documentation |
| man/dot-parse_nm_input.Rd | Internal helper documentation |
| man/dot-find_dose_variables.Rd | Internal helper documentation |
| NAMESPACE | Exports get_required_input_variables |
| DESCRIPTION | Version bump |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| # data_col defaults ----------------------------------------------------------- | ||
|
|
||
| test_that("data_col equals nonmem_name when no data argument given and $DATA file absent", { | ||
| out <- get_required_input_variables(simple_code) | ||
| expect_equal(out$data_col, out$nonmem_name) | ||
| }) |
There was a problem hiding this comment.
Tests that call get_required_input_variables(simple_code) (where simple_code contains $DATA data.csv) will typically emit a $DATA file ... not found warning because the model is passed as a code string and data.csv won’t exist in the test working directory. To keep test output clean (and avoid check notes about warnings during tests), consider removing $DATA from the in-memory snippets, creating a temporary data.csv via withr::local_dir() + write.csv(), or wrapping those calls in suppressWarnings()/expect_warning(..., NA) where appropriate.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…to get-covariates
Summary
dataargument (data.frame or CSV path) to populatedata_colfrom actual dataset column names via positional matching; auto-detects the dataset from$DATAwhen omitted, with a clear warning if the file cannot be found$INPUTrename parsing — NONMEM's rename syntax isNONMEM_NAME=DATA_COL(was reversed in.parse_nm_input)$INPUTentries (where positional matching would be unreliable)Test plan
devtools::test(filter = "get_required_input_variables")— covers all classification types (reserved, used/unused covariate, dose variable, dropped), data resolution paths (explicit data.frame, CSV file,$DATAauto-detect), edge cases (multi-line$INPUT, inline comments,IGNORE=C), and error conditionsdevtools::check()to confirm no regressions🤖 Generated with Claude Code