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.
modify_model_field(
.mod,
.field,
.value,
.append = TRUE,
.remove = FALSE,
.unique = TRUE,
.char_value = TRUE
)
replace_model_field(.mod, .field, .old_val, .new_val)
The bbi_{.model_type}_model
object to modify
Character scalar of the name of the component to modify
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.
If TRUE
, the default, concatenate new values with currently present values. If FALSE
, new values will overwrite old values.
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.
If TRUE
, the default, de-duplicate .mod[[.field]]
after adding new values. If FALSE
duplicate values will be kept.
If TRUE
, check that .value
(after unlisting) is a character vector.
The value to be replaced. If .old_val
is not present in
.mod[[.field]]
, function will warn user and return .mod
unchanged.
The value to insert in place of .old_val
in
.mod[[.field]]
.
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.
replace_model_field()
: Replace a single item in a model field