Last data update: 2014.03.03

R: Check names to comply to specific rules
checkNamesR Documentation

Check names to comply to specific rules

Description

Similar to checkNamed but you can pass the names directly.

Usage

checkNames(x, type = "named")

check_names(x, type = "named")

assertNames(x, type = "named", .var.name = vname(x), add = NULL)

assert_names(x, type = "named", .var.name = vname(x), add = NULL)

testNames(x, type = "named")

test_names(x, type = "named")

expect_names(x, type = "named", info = NULL, label = vname(x))

Arguments

x

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

type

[character(1)]
Select the check(s) to perform. “unnamed” checks x to be NULL. “named” (default) checks x for regular names which excludes names to be NA or empty (""). “unique” additionally tests for non-duplicated names. “strict” checks for unique names which comply to R's variable name restrictions. Note that you can use checkSubset to check for a specific set of names.

.var.name

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

add

[AssertCollection]
Collection to store assertion messages. See AssertCollection.

info

[character(1)]
Extra information to be included in the message for the testthat reporter. See expect_that.

label

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

Value

Depending on the function prefix: If the check is successful, the functions return TRUE. If the check is not successful, assertNamed/assert_named throws an error message, testNamed/test_named returns FALSE, and checkNamed returns a string with the error message. The function expect_named always returns an expectation.

Examples

x = 1:3
testNames(x, "unnamed")
names(x) = letters[1:3]
testNames(x, "unique")

Results