Check the class membership of an argument
Check the class membership of an argument
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) )
x |
[any] |
classes |
[ |
ordered |
[ |
null.ok |
[ |
.var.name |
[ |
add |
[ |
info |
[character(1)] |
label |
[ |
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
returns a string with the error message.
The function expect_class
always returns an
expectation
.
Other attributes:
checkMultiClass()
,
checkNamed()
,
checkNames()
Other classes:
checkMultiClass()
,
checkR6()
# 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)
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.