Replace a section in a ferx model (pipe-friendly)
Description
Updates the body of a named section in a .ferx model file and returns the input object so calls can be chained with |> or %>%.
Usage
ferx_set_section(x, section, lines)Arguments
x: Aferx_modelobject or a path to a.ferxfile.section: Name of the section to replace, without brackets.lines: Character vector of replacement lines (do not include the header line).
Details
When x is a ferx_model object the section is written to x$model and x is returned invisibly, allowing further pipe steps. Copy-on-write for bundled examples: if x$modelpoints to a file inside the installed ferx package directory (typically the result of [ferx_example](ferx_example.qmd)()), the file is first copied to tempdir() and x$model is updated to that copy before the edit. This prevents accidental modification of read-only package examples. When x is a plain path string the call is equivalent to [ferx_model_set_section](ferx_model_set_section.qmd)(x, section, lines)and the file is edited in place.
Seealso
[ferx_model_set_section](ferx_model_set_section.qmd), [ferx_get_section](ferx_get_section.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_model_validate](ferx_model_validate.qmd)()
Concept
model-editing
Value
x, invisibly. For a ferx_model pointing at a bundled package file, the returned object’s $model field will point at the temp-directory copy that was actually edited.
Examples
ex <- ferx_example("warfarin")
# Safe by default: editing a bundled example transparently copies the
# file to tempdir() and edits the copy. ex$model on disk is untouched.
fit <- ferx_model(ex$data, ex$model) |>
ferx_set_section("fit_options", c(
" method = focei",
" maxiter = 500",
" covariance = true"
)) |>
ferx_fit() |>
summary()