inheritance-expectations

0th

Percentile

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

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

See Also

inherits()

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

Aliases
  • inheritance-expectations
  • expect_null
  • expect_type
  • expect_is
  • expect_s3_class
  • expect_s4_class
Examples
# NOT RUN {
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)

# }
Documentation reproduced from package testthat, version 2.0.1, License: MIT + file LICENSE

Community examples

Looks like there are no examples yet.