Learn R Programming

checkmate (version 1.0)

checkClass: 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.
.var.name
[character(1)] Name for x. Defaults to a heuristic to determine the name using deparse and substitute.
classes
[character] Class names to check for inheritance with inherits.
ordered
[logical(1)] Expect x to be specialized in provided order. Default is FALSE.

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

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