Learn R Programming

checkmate (version 2.3.2)

checkPermutation: Check if the arguments are permutations of each other.

Description

In contrast to checkSetEqual, the function tests for a true permutation of the two vectors and also considers duplicated values. Missing values are being treated as actual values by default. Does not work on raw values.

Usage

checkPermutation(x, y, na.ok = TRUE)

check_permutation(x, y, na.ok = TRUE)

assertPermutation(x, y, na.ok = TRUE, .var.name = vname(x), add = NULL)

assert_permutation(x, y, na.ok = TRUE, .var.name = vname(x), add = NULL)

testPermutation(x, y, na.ok = TRUE)

test_permutation(x, y, na.ok = TRUE)

expect_permutation(x, y, na.ok = TRUE, info = NULL, label = vname(x))

Value

Depending on the function prefix: If the check is successful, the functions

assertPermutation/assert_permutation return

x invisibly, whereas

checkPermutation/check_permutation and

testPermutation/test_permutation return

TRUE. If the check is not successful,

assertPermutation/assert_permutation

throws an error message,

testPermutation/test_permutation

returns FALSE, and checkPermutation/check_permutation

return a string with the error message. The function expect_permutation always returns an

expectation.

Arguments

x

[any]
Object to check.

y

[atomic]
Vector to compare with. Atomic vector of type other than raw.

na.ok

[logical(1)]
Are missing values allowed? Default is TRUE.

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

See Also

Other set: checkChoice(), checkDisjunct(), checkSetEqual(), checkSubset()

Examples

Run this code
testPermutation(letters[1:2], letters[2:1])
testPermutation(letters[c(1, 1, 2)], letters[1:2])
testPermutation(c(NA, 1, 2), c(1, 2, NA))
testPermutation(c(NA, 1, 2), c(1, 2, NA), na.ok = FALSE)

Run the code above in your browser using DataLab