Skip to contents

Validity check capable of validating multiple slots in a single call.

Usage

validateClasses(object, expected, subset = FALSE)

Arguments

object

Object.

expected

list. Named list of expected classes per slot.

subset

logical(1). Only check a subset of slots in the object.

Value

logical(1) (TRUE) on sucess or character(1) containing informative message on failure.

Details

To be used inside S4 setValidity() call or with validate(). Particularly useful for checking multiple slotted objects inside metadata().

Note

Updated 2023-04-26.

Examples

## TRUE ====
validateClasses(
    object = list(
        "a" = character(),
        "b" = integer(),
        "c" = factor()
    ),
    expected = list(
        "a" = "character",
        "b" = "integer",
        "c" = "factor"
    )
)
#> [1] TRUE

## FALSE ====
validateClasses(
    object = list(
        "a" = character(),
        "b" = integer(),
        "c" = factor()
    ),
    expected = list(
        "a" = "character",
        "b" = "character",
        "c" = "character"
    )
)
#> [1] "Class checks failed: b, c.\nIf supported, 'updateObject()' may help resolve these issues."