Skip to content

Add drop_input argument to create_model()#58

Merged
roninsightrx merged 2 commits intomainfrom
drop-input-arg
Apr 2, 2026
Merged

Add drop_input argument to create_model()#58
roninsightrx merged 2 commits intomainfrom
drop-input-arg

Conversation

@roninsightrx
Copy link
Copy Markdown
Contributor

Summary

  • Adds a drop_input argument to create_model() that accepts a character vector of column names to mark as DROP in the NONMEM $INPUT record
  • Validates that data is supplied and that all specified columns exist in the dataset
  • Implements via string manipulation of $INPUT (same pattern as set_dv())

Test plan

  • Test with drop_input = c("COL1", "COL2") and verify $INPUT contains DROP in place of those columns
  • Test that an error is thrown when drop_input is used without data
  • Test that an error is thrown when a non-existent column name is specified
  • Verify existing create_model() behavior is unchanged when drop_input = NULL

🤖 Generated with Claude Code

Allows users to specify column names to mark as DROP in the NONMEM $INPUT
record. Validates that data is supplied and columns exist in the dataset.

Co-Authored-By: Claude Opus 4.6 (1M context) <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 support in create_model() for dropping specific dataset columns from the NONMEM $INPUT record by marking them as DROP, with corresponding documentation updates.

Changes:

  • Added drop_input argument to create_model() and implemented $INPUT rewriting via new drop_input_columns() helper.
  • Regenerated/added roxygen2 docs (man/create_model.Rd, new man/drop_input_columns.Rd) and updated create_regimen Rd usage ordering.
  • Bumped package version in DESCRIPTION.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
R/create_model.R Adds drop_input argument, validates inputs, and introduces $INPUT rewriting helper.
man/drop_input_columns.Rd New roxygen2-generated documentation for drop_input_columns().
man/create_regimen.Rd Roxygen2 regeneration adjusts argument ordering in usage/arguments.
man/create_model.Rd Roxygen2 regeneration adds drop_input to docs.
DESCRIPTION Version bump.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

new_code <- paste(lines, collapse = "\n")
tmpmod <- tempfile(fileext = ".mod")
writeLines(new_code, tmpmod)
create_model_from_file(tmpmod, data = model$dataset)
Copy link

Copilot AI Apr 1, 2026

Choose a reason for hiding this comment

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

drop_input_columns() rebuilds the model via create_model_from_file(tmpmod, data = model$dataset), but create_model_from_file() re-reads the model with read_model_from_string() and drops the loaded dataset. This means using drop_input will likely return a model with mod$dataset == NULL and can break subsequent logic in create_model() (e.g., BLQ checks immediately after this block rely on names(mod$dataset)). Re-attach the original dataset to the returned model (e.g., capture data <- model$dataset and call pharmr::set_dataset(new_model, path_or_df = data, datatype = 'nonmem') after re-reading, or avoid create_model_from_file() and use read_model_from_string() + explicit set_dataset() like other helpers do).

Suggested change
create_model_from_file(tmpmod, data = model$dataset)
data <- model$dataset
new_model <- create_model_from_file(tmpmod, data = data)
if (!is.null(data)) {
new_model <- pharmr::set_dataset(new_model, path_or_df = data, datatype = "nonmem")
}
new_model

Copilot uses AI. Check for mistakes.
- Replace standalone column names with DROP=<col> (preserves original name)
- Add validation for non-character drop_input and missing columns
- Add test-drop_input.R covering drop_input_columns directly and
  create_model() validation, including datainfo$drop checks

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@roninsightrx roninsightrx merged commit dca558c into main Apr 2, 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