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, ...)
x | An object with one of the pensieve S3 classes. |
---|---|
... | further arguments to be passed to methods. |
ps_coll |
|
info | [ |
label | [ |
collection | [ |
var.name | [ |
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:
expect_S3()
always returns an testthat::expectation()
for internal use in testing,
shiny package extension:
need_S3()
returns NULL
or the error message for internal use with the accio web frontend inside shiny::validate()
.
# 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)#> NULLvalidate_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] TRUEcheck_S3(bad_obj)#> * Variable 'items': Must be of type 'character', not 'psItemContentText/psItemContent/character'. #> * Variable 'items': Must have names.test_S3(good_obj)#> [1] TRUEtest_S3(bad_obj)#> [1] FALSEexpect_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)#> NULLneed_S3(bad_obj)#> [1] ": * Variable 'items': Must be of type 'character', not 'psItemContentText/psItemContent/character'.\n* Variable 'items': Must have names."