modify_model_field: Modify field in model object

View source: R/modify-model-field.R

modify_model_fieldR Documentation

Modify field in model object

Description

Helper functions for updating fields in a ⁠bbi_{.model_type}_model⁠ object. Note that calling modify_model_field() or replace_model_field() directly is not recommended for most users because it requires knowing about the internal structure of the model object. Instead, we recommend using the friendlier helpers listed below in "See also" whenever possible.

Usage

modify_model_field(
  .mod,
  .field,
  .value,
  .append = TRUE,
  .remove = FALSE,
  .unique = TRUE,
  .char_value = TRUE
)

replace_model_field(.mod, .field, .old_val, .new_val)

Arguments

.mod

The ⁠bbi_{.model_type}_model⁠ object to modify

.field

Character scalar of the name of the component to modify

.value

Whatever is to be added to .mod[[.field]], typically a character vector (or a named list in the case of ⁠*_bbi_args()⁠). If NULL or NA is passed and .append = FALSE then .field with be deleted from the object and corresponding YAML.

.append

If TRUE, the default, concatenate new values with currently present values. If FALSE, new values will overwrite old values.

.remove

If TRUE, .value with be removed from the .field instead of added. FALSE by default. Cannot have both .append and .remove be true in the same call.

.unique

If TRUE, the default, de-duplicate .mod[[.field]] after adding new values. If FALSE duplicate values will be kept.

.char_value

If TRUE, check that .value (after unlisting) is a character vector.

.old_val

The value to be replaced. If .old_val is not present in .mod[[.field]], function will warn user and return .mod unchanged.

.new_val

The value to insert in place of .old_val in .mod[[.field]].

Details

All functions in this family also check the object against the corresponding YAML with check_yaml_in_sync() before modifying it, and errors if they are out of sync. After the object has been modified they will write the modified object back to the YAML and update the model object in memory with an md5 digest of the newly written YAML.

Functions

  • replace_model_field(): Replace a single item in a model field

See Also

add_tags() replace_tag() replace_all_tags() remove_tags() add_notes() replace_note() replace_all_notes() remove_notes() add_based_on() replace_all_based_on() remove_based_on() add_description() replace_description() add_bbi_args() replace_all_bbi_args() modify_star()


metrumresearchgroup/rbabylon documentation built on April 21, 2024, 3:26 a.m.