check_length: Check if vectors are of compatible lengths

View source: R/checkmate.R

check_lengthR Documentation

Check if vectors are of compatible lengths

Description

[Stable]

Two vectors are of compatible size if and only if:

  1. At least one vector has size 1

  2. or both vectors are of the same size.

Usage

check_length(x, len)

assert_length(x, len, .var.name = checkmate::vname(x), add = NULL)

test_length(x, len)

Arguments

x

(any)
the first vector, any object for which length() function is defined.

len

(count)
the length of the second vector.

.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.

Value

TRUE if successful, otherwise a string with the error message.

See Also

assertions for more details.

Examples

check_length(1:5, 1)
check_length(1:5, 6)
check_length(1:5, 5)
check_length(10, 1)
check_length(10, 9)

Roche/crmPack documentation built on April 20, 2024, 1:10 p.m.