Check whether a prospective node name is valid, sanitize it, and return it

nodeName(
  x,
  entityName = NULL,
  thisEntityText = "this entity (with temporary name '%s')"
)

Arguments

x

The prospective node name

entityName

The original name of the entity before renaming

thisEntityText

Text to insert with the the current name of this entity, in case it's about to be renamed.

Value

The (sanitized) node name

Examples

metabefor::nodeName("this_is_valid");
#> [1] "this_is_valid"
metabefor::nodeName("this is sanitized");
#> [1] "thisissanitized"
if (FALSE) {
  metabefor::nodeName(
    "_thisThrowsAnError:first character can't be _"
  );
  ### This also throws an error: a reserved name by data.tree
  metabefor::nodeName(
    "parent"
  );
}