Learn R Programming

checkmate (version 1.7.3)

checkNamed: Check if an argument is named

Description

Check if an argument is named

Usage

checkNamed(x, type = "named")

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

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

testNamed(x, type = "named")

test_named(x, type = "named")

Arguments

x
[any] Object to check.
type
[character(1)] Select the check(s) to perform. unnamed checks x to be unnamed. named (default) checks x to be named which excludes names to be NA or empty ("").
add
[AssertCollection] Collection to store assertions. See AssertCollection.
.var.name
[NULL || character(1)] Name of the checked object to print in error message. If NULL, the name will be heuristically determined via substitute.

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
testNamed(x, "unnamed")
names(x) = letters[1:3]
testNamed(x, "unique")

Run the code above in your browser using DataLab