Learn R Programming

checkmate (version 1.7.4)

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, .var.name = vname(x), add = NULL)

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

testClass(x, classes, ordered = FALSE)

test_class(x, classes, ordered = FALSE)

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

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