Add drop_input argument to create_model()#58
Conversation
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>
There was a problem hiding this comment.
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_inputargument tocreate_model()and implemented$INPUTrewriting via newdrop_input_columns()helper. - Regenerated/added roxygen2 docs (
man/create_model.Rd, newman/drop_input_columns.Rd) and updatedcreate_regimenRd 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) |
There was a problem hiding this comment.
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).
| 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 |
- 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>
Summary
drop_inputargument tocreate_model()that accepts a character vector of column names to mark asDROPin the NONMEM$INPUTrecorddatais supplied and that all specified columns exist in the dataset$INPUT(same pattern asset_dv())Test plan
drop_input = c("COL1", "COL2")and verify$INPUTcontainsDROPin place of those columnsdrop_inputis used withoutdatacreate_model()behavior is unchanged whendrop_input = NULL🤖 Generated with Claude Code