testthat (version 1.0.2)

inheritance-expectations: Expectation: does the object inherit from a S3 or S4 class, or a base type?

Description

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.

Usage

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 convery intent.

See Also

inherits

Other expectations: comparison-expectations, equality-expectations, expect_equal_to_reference, expect_length, expect_match, expect_named, logical-expectations, output-expectations

Examples

Run this code
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)

Run the code above in your browser using DataLab