assert_range() checks that an output field, converted to a number, lies
within min and max. A value that cannot be converted fails the check.
Usage
assert_range(
field = NULL,
min = NULL,
max = NULL,
type = c("assert", "suggest")
)Arguments
- field
The output field to check. With
NULL, the whole output is checked, which suits outputs with a single field. A missing field fails the check.- min, max
Inclusive bounds. Give at least one.
- type
"assert"(the default) for a hard assertion, which makeswith_assertions()retry when it fails, or"suggest"for a soft one, which only gives a warning.
Value
An assertion for assertion_set() or with_assertions().
Examples
assert_range("score", min = 0, max = 100)
#>
#> ── Hard Assertion
#> • Field: any field
#> • Message: "score: Value must be between 0 and 100"
assert_range("confidence", min = 0, type = "suggest")
#>
#> ── Soft Suggestion
#> • Field: any field
#> • Message: "confidence: Value must be at least 0"