Use validate_S3(), check_S3(), test_S3(), assert_S3(), expect_S3() and need_S3() to validate S3 objects from this package.

validate_S3(x, ...)

# S3 method for default
validate_S3(x, ps_coll = NULL, ...)

check_S3(x, ...)

test_S3(x, ...)

expect_S3(x, info = NULL, label = NULL, ...)

assert_S3(x, collection = NULL, var.name = NULL, ...)

need_S3(x, label = NULL, ...)

Arguments

x

An object with one of the pensieve S3 classes.

...

further arguments to be passed to methods.

ps_coll

AssertCollection ps_coll error collection via checkmate::makeAssertCollection(), for internal use.

info

[character(1)]
See expect_that

label

[character(1)]
See expect_that

collection

[AssertCollection]
If an AssertCollection is provided, the error message is stored in it. If NULL, an exception is raised if res is not TRUE.

var.name

[character(1)]
The custom name for x as passed to any assert* function. Defaults to a heuristic name lookup.

Details

All S3 classes in pensieve have validate_S3() methods, which return NULL on success, or a character vector of arbitrary length with validation failures. Five alternative generics use the same underlying validate_S3() methods, but differ in their returns:

  • checkmate package extensions:

    • check_S3() returns TRUE or the error message as a character string,

    • assert_S3() returns x invisibly or throws an error,

    • test_S3() returns TRUE or FALSE,

  • testthat) package extension:

  • shiny package extension:

    • need_S3() returns NULL or the error message for internal use with the accio web frontend inside shiny::validate().

Examples

# just for testing; never build objects like this by hand good_obj <- psItemContent(items = "I am an item") bad_obj <- structure( .Data = 1L, # must be character class = c("psItemContentText", "psItemContent", "character") ) validate_S3(good_obj)
#> NULL
validate_S3(bad_obj)
#> [1] "Variable 'items': Must be of type 'character', not 'psItemContentText/psItemContent/character'." #> [2] "Variable 'items': Must have names."
check_S3(good_obj)
#> [1] TRUE
check_S3(bad_obj)
#> * Variable 'items': Must be of type 'character', not 'psItemContentText/psItemContent/character'. #> * Variable 'items': Must have names.
test_S3(good_obj)
#> [1] TRUE
test_S3(bad_obj)
#> [1] FALSE
expect_S3(good_obj) # expect_S3(bad_obj) # this errors out assert_S3(good_obj) # assert_S3(bad_obj) # this errors out need_S3(good_obj)
#> NULL
need_S3(bad_obj)
#> [1] ": * Variable 'items': Must be of type 'character', not 'psItemContentText/psItemContent/character'.\n* Variable 'items': Must have names."