Skip to content

Extend get_required_input_variables: Pharmpy object, data arg, bug fixes#47

Merged
roninsightrx merged 6 commits intomainfrom
get-covariates
Mar 27, 2026
Merged

Extend get_required_input_variables: Pharmpy object, data arg, bug fixes#47
roninsightrx merged 6 commits intomainfrom
get-covariates

Conversation

@roninsightrx
Copy link
Copy Markdown
Contributor

Summary

  • Accept Pharmpy model objects in addition to file paths and code strings
  • Add data argument (data.frame or CSV path) to populate data_col from actual dataset column names via positional matching; auto-detects the dataset from $DATA when omitted, with a clear warning if the file cannot be found
  • Fix $INPUT rename parsing — NONMEM's rename syntax is NONMEM_NAME=DATA_COL (was reversed in .parse_nm_input)
  • Relax column-count check — extra trailing data columns are trimmed rather than aborting; only warns when data has fewer columns than $INPUT entries (where positional matching would be unreliable)

Test plan

  • Run 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, $DATA auto-detect), edge cases (multi-line $INPUT, inline comments, IGNORE=C), and error conditions
  • Run devtools::check() to confirm no regressions

🤖 Generated with Claude Code

roninsightrx and others added 3 commits March 23, 2026 21:56
- 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>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 resolve data_col via data or $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.

Comment on lines +181 to +186
# 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)
})
Copy link

Copilot AI Mar 27, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
roninsightrx and others added 3 commits March 27, 2026 14:37
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@roninsightrx roninsightrx merged commit 6bf8061 into main Mar 27, 2026
2 checks passed
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.

2 participants