Skip to contents

Validates that the value belongs to a given class. One verb covers the types without a dedicated check, including factor, Date, POSIXct, list, and fitted-model objects such as lm.

Usage

require_class(restriction, class, exact = FALSE)

Arguments

restriction

a restriction object.

class

character(1) class name to require.

exact

logical; if TRUE, requires class(value)[1] to equal class exactly. If FALSE (default), tests inheritance with inherits(), so a subclass passes.

Value

The modified restriction object.

Examples

restrict("d") |> require_class("Date")
#> <restriction d>
#>   1. must be of class "Date"
restrict("f") |> require_class("factor")
#> <restriction f>
#>   1. must be of class "factor"
restrict("model") |> require_class("lm")
#> <restriction model>
#>   1. must be of class "lm"