Replace a section in a ferx model file

Description

Overwrites the body of a named section in a .ferx file with new lines, leaving all other sections untouched. Use this to modify a model programmatically without opening an editor.

Usage

ferx_model_set_section(path, section, lines)

Arguments

  • path: Path to a .ferx model file.
  • section: Name of the section to replace, without brackets (e.g. "fit_options").
  • lines: Character vector of replacement lines. These become the new body of the section (do not include the [section] header line).

Seealso

[ferx_model_section](ferx_model_section.qmd), [ferx_model_show](ferx_model_show.qmd), [ferx_model_new](ferx_model_new.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_show](ferx_model_show.qmd)(), [ferx_model_validate](ferx_model_validate.qmd)(), [ferx_set_section](ferx_set_section.qmd)()

Concept

model-editing

Value

path, invisibly.

Examples

# Switch estimation method without opening an editor
ferx_model_set_section("my_model.ferx", "fit_options", c(
  "  method     = focei",
  "  maxiter    = 500",
  "  covariance = false"
))

# Read-modify-write a section
lines <- ferx_model_section("my_model.ferx", "parameters")
lines <- sub("TVCL\\(.*\\)", "TVCL(0.5, 0.001, 10.0)", lines)
ferx_model_set_section("my_model.ferx", "parameters", lines)