Validate a ferx model file for syntax and structural errors
Description
Parses a .ferx model file using the Rust engine and checks for required sections, without running the optimizer. Useful for catching syntax errors and missing sections before committing to a long estimation run. This is the in-R counterpart to the ferx check CLI shipped with ferx-core and shares the same parser and structural diagnostics.
Usage
ferx_model_validate(path, data = NULL)Arguments
path: Path to a.ferxmodel file. The file must exist and have a.ferxextension; otherwise an error is raised (these are caller errors, not validation failures).data: Optional path to a NONMEM-format CSV. When supplied, the engine additionally runs data-dependent checks (covariate columns present, per-CMT scaling/error-model coverage, steady-state II sanity, lagtime signs).NULLruns the model-only checks.
Seealso
[ferx_model_inspect](ferx_model_inspect.qmd), [ferx_model_show](ferx_model_show.qmd)Other model-editing: [ferx_get_section](ferx_get_section.qmd)(), [ferx_model](ferx_model.qmd)(), [ferx_model_edit](ferx_model_edit.qmd)(), [ferx_model_inspect](ferx_model_inspect.qmd)(), [ferx_model_new](ferx_model_new.qmd)(), [ferx_model_section](ferx_model_section.qmd)(), [ferx_model_set_section](ferx_model_set_section.qmd)(), [ferx_model_show](ferx_model_show.qmd)(), [ferx_set_section](ferx_set_section.qmd)()
Concept
model-editing
Value
Invisibly returns a list with ok (logical), model, data, and a diagnostics data frame with one row per finding (severity, code, message, block, line, suggestion). The function always prints a report to the console. Codes are stable identifiers (E_* for errors, W_* for warnings) suitable for programmatic handling - the registry lives in ferx-core’s docs/src/file-formats/check-report.md. A missing file or non-.ferx extension raises an error rather than returning a failed diagnostic.
Examples
# Valid model
ex <- ferx_example("warfarin")
ferx_model_validate(ex$model)
# With data-dependent checks
ferx_model_validate(ex$model, data = ex$data)
# Inspect findings programmatically
res <- ferx_model_validate(ex$model)
res$ok
res$diagnostics
# Invalid model (missing required sections)
bad <- tempfile(fileext = ".ferx")
writeLines(c(
"[parameters]",
" theta TVCL(1.0, 0.001, 100.0)",
"[structural_model]",
" pk one_cpt_oral(cl=CL, v=V, ka=KA)"
), bad)
ferx_model_validate(bad)
# Validating: <file>.ferx
#
# Sections present:
# parameters [ok]
# individual_parameters [MISSING]
# structural_model [ok]
# error_model [MISSING]
#
# Result: INVALID
# * Missing required section: [individual_parameters]
# * Missing required section: [error_model]