Learn R Programming

testthat (version 0.6)

is_a: Expectation: does the object inherit from a class?

Description

Tests whether or not an object inherits from any of a list of classes.

Usage

is_a(class)

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

Arguments

class
character vector of class names
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.

See Also

inherits

Other expectations: equals, expect_equal, expect_equivalent, expect_error, expect_false, expect_identical, expect_match, expect_message, expect_output, expect_true, expect_warning, gives_warning, is_equivalent_to, is_false, is_identical_to, is_true, matches, prints_text, shows_message, takes_less_than, throws_error

Examples

Run this code
expect_that(1, is_a("numeric"))
a <- matrix(1:10, nrow = 5)
expect_that(a, is_a("matrix"))

expect_that(mtcars, is_a("data.frame"))
expect_is(mtcars, "data.frame")
# alternatively for classes that have an is method
expect_that(is.data.frame(mtcars), is_true())
# doesn't read quite as nicely

Run the code above in your browser using DataLab