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}_modelobject 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()). IfNULLorNAis passed and.append = FALSEthen.fieldwith be deleted from the object and corresponding YAML.- .append
If
TRUE, the default, concatenate new values with currently present values. IfFALSE, new values will overwrite old values.- .remove
If
TRUE,.valuewith be removed from the.fieldinstead of added.FALSEby default. Cannot have both.appendand.removebe true in the same call.- .unique
If
TRUE, the default, de-duplicate.mod[[.field]]after adding new values. IfFALSEduplicate 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_valis not present in.mod[[.field]], function will warn user and return.modunchanged.- .new_val
The value to insert in place of
.old_valin.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.
