Performs various checks on character vectors, usually names.
Usage
checkNames(
x,
type = "named",
subset.of = NULL,
must.include = NULL,
permutation.of = NULL,
identical.to = NULL,
disjunct.from = NULL,
what = "names"
)
check_names(
x,
type = "named",
subset.of = NULL,
must.include = NULL,
permutation.of = NULL,
identical.to = NULL,
disjunct.from = NULL,
what = "names"
)
assertNames(
x,
type = "named",
subset.of = NULL,
must.include = NULL,
permutation.of = NULL,
identical.to = NULL,
disjunct.from = NULL,
what = "names",
.var.name = vname(x),
add = NULL
)
assert_names(
x,
type = "named",
subset.of = NULL,
must.include = NULL,
permutation.of = NULL,
identical.to = NULL,
disjunct.from = NULL,
what = "names",
.var.name = vname(x),
add = NULL
)
testNames(
x,
type = "named",
subset.of = NULL,
must.include = NULL,
permutation.of = NULL,
identical.to = NULL,
disjunct.from = NULL,
what = "names"
)
test_names(
x,
type = "named",
subset.of = NULL,
must.include = NULL,
permutation.of = NULL,
identical.to = NULL,
disjunct.from = NULL,
what = "names"
)
expect_names(
x,
type = "named",
subset.of = NULL,
must.include = NULL,
permutation.of = NULL,
identical.to = NULL,
disjunct.from = NULL,
what = "names",
info = NULL,
label = vname(x)
)Arguments
- x
[
character||NULL]
Names to check using rules defined viatype.- type
[
character(1)]
Type of formal check(s) to perform on the names.- unnamed:
Checks
xto beNULL.- named:
Checks
xfor regular names which excludes names to beNAor 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 toTRUE.- subset.of
[
character]
Names provided inxmust be subset of the setsubset.of.- must.include
[
character]
Names provided inxmust be a superset of the setmust.include.- permutation.of
[
character]
Names provided inxmust be a permutation of the setpermutation.of. Duplicated names inpermutation.ofare stripped out and duplicated names inxthus lead to a failed check. Use this argument instead ofidentical.toif the order of the names is not relevant.- identical.to
[
character]
Names provided inxmust be identical to the vectoridentical.to. Use this argument instead ofpermutation.ofif the order of the names is relevant.- disjunct.from
[
character]
Names provided inxmust may not be present in the vectordisjunct.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 assertions. Defaults to the heuristic implemented invname.- add
[
AssertCollection]
Collection to store assertion messages. SeeAssertCollection.- info
[
character(1)]
Extra information to be included in the message for the testthat reporter. Seeexpect_that.- label
[
character(1)]
Name of the checked object to print in messages. Defaults to the heuristic implemented invname.
Value
Depending on the function prefix:
If the check is successful, the functions
assertNames/assert_names return
x invisibly, whereas
checkNames/check_names and
testNames/test_names return
TRUE.
If the check is not successful,
assertNames/assert_names
throws an error message,
testNames/test_names
returns FALSE,
and checkNames/check_names
return a string with the error message.
The function expect_names always returns an
expectation.
See also
Other attributes:
checkClass(),
checkMultiClass(),
checkNamed()