Skip to content

model_from_api() stores file path as nonmem/ferx attribute when definition lacks implementation #148

Open

Description

@roninsightrx

Problem

In model_from_api() (R/model_from_api.R:43-48), the NONMEM / FeRx file is only read when the model definition also lists the implementation:

if(!is.null(nonmem) && !is.null(def$implementations$nonmem)) {
  nonmem <- paste(readLines(nonmem), collapse="\n")
}
if(!is.null(ferx) && !is.null(def$implementations$ferx)) {
  ferx <- paste(readLines(ferx), collapse="\n")
}

If a nonmem or ferx path is passed but def$implementations$<type> is NULL, the variable keeps its value, which is the path string. That string is then passed to new_ode_model() and stored as the model's nonmem / ferx attribute, as if it were model code.

Reproduce

mod <- model_from_api(
  url = test_path("sample_json", "test_1cmt_iv.json5"),  # no `implementations` field
  ferx = "path/to/model.ferx",
  to_package = TRUE,
  force = TRUE
)
attr(test1cmtiv::model(), "ferx")
#> "path/to/model.ferx"

Expected

Either:

  • reset to NULL when the definition does not list the implementation (possibly with a message when verbose), or
  • read the file regardless of def$implementations.

The first option matches what the current check seems to intend.

Found while reviewing #146.

🤖 Generated with Claude Code

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions