Learn R Programming

testextra (version 0.1.0.1)

class-tests: Enhanced Class Tests

Description

These tests allow for mapped and enhanced tests regarding class.

Usage

all_inherit(lst, class, label = NULL)

are(lst, class)

is_exactly(object, class)

all_are_exactly(lst, class, label = NULL)

Arguments

lst

A list of objects to test

class

The class object is to be, or classes it is allowed to be.

label

object label. When NULL, computed from deparsed object.

object

An object to test

Functions

  • all_inherit: Check if all elements of a list are or inherit from the given class. Uses base::inherits() to check inheritance.

  • are: methods::is mapped over a vector. Similar to all_inherit but uses methods::is() for test. This manifests in S4 Virtual classes such as the 'ANY' class

  • is_exactly: Test that an object is exactly a class; excludes inheritance.

  • all_are_exactly: Version of is_exactly for all elements of a list.

See Also

Other class: class-expectations

Examples

Run this code
# NOT RUN {
lst <- list(1L, 2, TRUE)

# all_inherit uses `inherits`
all_inherit(lst, 'numeric')
all_inherit(lst, 'integer')
all_inherit(lst, 'ANY')

# are uses `is` so gets different results.
are(lst, "numeric")
are(lst, "integer")
are(lst, "ANY")

# is_exactly the class must match exactly
is_exactly(1L, "integer")
# no inheritance allowed
is_exactly(1L, "numeric")
# }

Run the code above in your browser using DataLab