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 .ferx model file.
  • dest: Directory to copy read-only package files into before editing. Defaults to the current working directory. Ignored when path is already a writable user-owned file.
  • overwrite: Logical. If TRUE, overwrite an existing file in dest when copying a package example. If FALSE (default) and the destination file already exists, an error is raised.
  • save_as: Controls post-edit save-as behaviour:
  • NULL or FALSE (default) - no extra action after editing. Accepting FALSE lets you pass expressions like save_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 to utils::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)