Tests whether or not an object inherits from any of a list of classes, or is an instance of a base type. expect_null() is a special case designed for detecting NULL.

expect_null(object, info = NULL, label = NULL)

expect_type(object, type)

expect_is(object, class, info = NULL, label = NULL)

expect_s3_class(object, class)

expect_s4_class(object, class)

Arguments

object

object to test

info

extra information to be included in the message (useful when writing tests in loops).

label

object label. When NULL, computed from deparsed object.

type

String giving base type (as returned by typeof()).

class

character vector of class names

Details

expect_is() is an older form. I'd recommend using expect_s3_class() or expect_s4_class() in order to more clearly convey intent.

See also

Examples

expect_is(1, "numeric") a <- matrix(1:10, nrow = 5) expect_is(a, "matrix") expect_is(mtcars, "data.frame") # alternatively for classes that have an is method expect_true(is.data.frame(mtcars)) f <- factor("a") expect_is(f, "factor") expect_s3_class(f, "factor") expect_type(f, "integer") expect_null(NULL)