Learn R Programming

checkmate (version 1.7.4)

checkNames: Check names to comply to specific rules

Description

Similar to checkNamed but you can pass the names directly.

Usage

checkNames(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 (""
.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

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

Run the code above in your browser using DataLab