validate_S3: Validate S3 classes from pensieve

Description Usage Arguments Details Examples

View source: R/checks.R

Description

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

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
validate_S3(x, ...)

## Default S3 method:
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:

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
# 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)
validate_S3(bad_obj)
check_S3(good_obj)
check_S3(bad_obj)
test_S3(good_obj)
test_S3(bad_obj)
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)
need_S3(bad_obj)

maxheld83/pensieve documentation built on Jan. 21, 2020, 9:16 a.m.