assert_names: Check names to comply to specific rules

assert_namesR Documentation

Check names to comply to specific rules

Description

Performs assertions with various checks on character vectors, usually names.

Usage

assert_names(
  x,
  type = "named",
  subset.of = NULL,
  must.include = NULL,
  permutation.of = NULL,
  identical.to = NULL,
  disjunct.from = NULL,
  what = "names",
  .var.name = checkmate::vname(x),
  comment = NULL,
  add = NULL
)

Arguments

x

[character || NULL]
Names to check using rules defined via type.

type

[character(1)]
Type of formal check(s) to perform on the names.

unnamed:

Checks x to be NULL.

named:

Checks x for regular names which excludes names to be NA or empty ("").

unique:

Performs checks like with “named” and additionally tests for non-duplicated names.

strict:

Performs checks like with “unique” and additionally fails for names with UTF-8 characters and names which do not comply to R's variable name restrictions. As regular expression, this is “^[.][a-zA-Z]+[a-zA-Z0-9._]$”.

ids:

Same as “strict”, but does not enforce uniqueness.

Note that for zero-length x, all these name checks evaluate to TRUE.

subset.of

[character]
Names provided in x must be subset of the set subset.of.

must.include

[character]
Names provided in x must be a superset of the set must.include.

permutation.of

[character]
Names provided in x must be a permutation of the set permutation.of. Duplicated names in permutation.of are stripped out and duplicated names in x thus lead to a failed check. Use this argument instead of identical.to if the order of the names is not relevant.

identical.to

[character]
Names provided in x must be identical to the vector identical.to. Use this argument instead of permutation.of if the order of the names is relevant.

disjunct.from

[character]
Names provided in x must may not be present in the vector disjunct.from.

what

[character(1)]
Type of name vector to check, e.g. “names” (default), “colnames” or “rownames”.

.var.name

[character(1)]
Name of the checked object to print in error messages. Defaults to the heuristic implemented in vname.

comment

[character(1)]
Extra information to be appended to the standard error message in assertions.

add

[AssertCollection]
Collection to store assertions. See AssertCollection.

Details

The assertions are based on checkmate::checkNames. NVIcheckmate::assert_names differs from checkmate::assert_names in including the argument comment = . The help is updated to reflect the changes.

Value

If the check is successful, the function assert_names return x invisibly.
If the check is not successful, assert_names throws an error message.


NorwegianVeterinaryInstitute/NVIcheckmate documentation built on Dec. 14, 2024, 10:43 p.m.