checkClass {checkmate}R Documentation

Check argument inheritance

Description

Check argument inheritance

Usage

checkClass(x, classes, ordered = FALSE)

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

testClass(x, classes, ordered = FALSE)

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 for x. Defaults to a heuristic to determine the name using deparse and substitute.

Value

Depending on the function prefix: If the check is successful, all functions return TRUE. If the check is not successful, assertClass throws an error message, testClass returns FALSE and checkClass returns a string with the error message.

Examples

# 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)

[Package checkmate version 1.6.0 Index]