checkClass {checkmate} | R Documentation |
Check the class membership of an argument
Description
Check the class membership of an argument
Usage
checkClass(x, classes, ordered = FALSE, null.ok = FALSE)
check_class(x, classes, ordered = FALSE, null.ok = FALSE)
assertClass(
x,
classes,
ordered = FALSE,
null.ok = FALSE,
.var.name = vname(x),
add = NULL
)
assert_class(
x,
classes,
ordered = FALSE,
null.ok = FALSE,
.var.name = vname(x),
add = NULL
)
testClass(x, classes, ordered = FALSE, null.ok = FALSE)
test_class(x, classes, ordered = FALSE, null.ok = FALSE)
expect_class(
x,
classes,
ordered = FALSE,
null.ok = FALSE,
info = NULL,
label = vname(x)
)
Arguments
x |
[any] |
classes |
[ |
ordered |
[ |
null.ok |
[ |
.var.name |
[ |
add |
[ |
info |
[ |
label |
[ |
Value
Depending on the function prefix:
If the check is successful, the functions
assertClass
/assert_class
return
x
invisibly, whereas
checkClass
/check_class
and
testClass
/test_class
return
TRUE
.
If the check is not successful,
assertClass
/assert_class
throws an error message,
testClass
/test_class
returns FALSE
,
and checkClass
/check_class
return a string with the error message.
The function expect_class
always returns an
expectation
.
See Also
Other attributes:
checkMultiClass()
,
checkNamed()
,
checkNames()
Other classes:
checkMultiClass()
,
checkR6()
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 of class "foo" or "bar"?
## Not run:
assert(
checkClass(x, "foo"),
checkClass(x, "bar")
)
## End(Not run)
# is x most specialized as "bar"?
testClass(x, "bar", ordered = TRUE)