checkmate (version 1.7.2)

checkClass: Check the class membership of an argument

Description

Check the class membership of an argument

Usage

checkClass(x, classes, ordered = FALSE)

assertClass(x, classes, ordered = FALSE, add = NULL, .var.name)

assert_class(x, classes, ordered = FALSE, add = NULL, .var.name)

testClass(x, classes, ordered = FALSE)

test_class(x, classes, ordered = FALSE)

expect_class(x, classes, ordered = FALSE, info = NULL, label = NULL)

Arguments

x
[any] Object to check.
classes
[character] Class names to check for inheritance with inherits.
ordered
[logical(1)] Expect x to be specialized in provided order. Default is FALSE.
add
[AssertCollection] Collection to store assertions. See AssertCollection.
.var.name
[character(1)] Name for x. Defaults to a heuristic to determine the name using deparse and substitute.
info
[character(1)] Extra information to be included in the message for the testthat reporter. See expect_that.
label
[character(1)] Same as .var.name, but passed down to expect_that.

Value

  • Depending on the function prefix: If the check is successful, the functions return TRUE. If the check is not successful, assertClass/assert_class throws an error message, testClass/test_class returns FALSE, and checkClass returns a string with the error message. The function expect_class always returns an expectation.

Examples

Run this code
# Create an object with classes "foo" and "bar"
x = 1
class(x) = c("foo", "bar")

# is x of class "foo"?
testClass(x, "foo")

# is x of class "foo" and "bar"?
testClass(x, c("foo", "bar"))

# is x most specialized as "bar"?
testClass(x, "bar", ordered = TRUE)

Run the code above in your browser using DataCamp Workspace