Open a ferx model file in an editor
Description
Opens a .ferx model file for editing. If the file lives inside the installed ferx package directory (i.e. a bundled read-only example), a copy is written to dest first and that copy is opened instead.
Usage
ferx_model_edit(
path,
dest = ".",
overwrite = FALSE,
save_as = NULL,
.editor = utils::file.edit
)Arguments
path: Path to a.ferxmodel file.dest: Directory to copy read-only package files into before editing. Defaults to the current working directory. Ignored whenpathis already a writable user-owned file.overwrite: Logical. IfTRUE, overwrite an existing file indestwhen copying a package example. IfFALSE(default) and the destination file already exists, an error is raised.save_as: Controls post-edit save-as behaviour:NULLorFALSE(default) - no extra action after editing. AcceptingFALSElets you pass expressions likesave_as = interactive().TRUE- interactively prompt the user for a destination path.- A character string - silently copy the edited file to that path.When a copy is made the copy path is returned; otherwise the edited file path is returned.
.editor: Function used to open the file. Defaults toutils::file.edit. Override in tests or non-interactive contexts to replace or suppress the editor call.
Details
After the editor closes, an optional save_as step lets you copy the edited file to a new path - useful when iterating on a model to keep versioned copies.
Seealso
[ferx_model_show](ferx_model_show.qmd), [ferx_model_new](ferx_model_new.qmd), [ferx_example](ferx_example.qmd)Other model-editing: [ferx_get_section](ferx_get_section.qmd)(), [ferx_model](ferx_model.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)(), [ferx_set_section](ferx_set_section.qmd)()
Concept
model-editing
Value
The path of the file in its final location, invisibly. When save_as produces a copy, that copy’s path is returned; otherwise the path of the edited file is returned.
Examples
ex <- ferx_example("warfarin")
# Edit a copy of the bundled example in a temp directory
my_model <- ferx_model_edit(ex$model, dest = tempdir())
# Edit a user-owned model directly
ferx_model_edit("my_model.ferx")
# After editing, save a copy to a new versioned path
ferx_model_edit("run1.ferx", save_as = "run2.ferx")
# After editing, interactively ask for the destination
ferx_model_edit("run1.ferx", save_as = TRUE)