validate_that: Validate that certain conditions are true.

Description Usage Arguments Value See Also Examples

Description

validate_that is an alternative to the function assert_that, that returns a character vector. This makes them easier to use within S4 "validate" methods.

Usage

1

Arguments

...

unnamed expressions that describe the conditions to be tested. Rather than combining expressions with &&, separate them by commas so that better error messages can be generated.

env

(advanced use only) the environment in which to evaluate the assertions.

msg

a custom error message to be printed if one of the conditions is false.

Value

A character vector if the assertion is false, or TRUE if the assertion is true.

See Also

assert_that, which returns an error if the condition is false.

Examples

1
2
3
4
5
6
7
x <- 1
# assert_that() generates errors, so can't be usefully run in
# examples
validate_that(is.numeric(x))
validate_that(is.character(x))
validate_that(length(x) == 3)
validate_that(is.dir("asdf"))

Example output

[1] TRUE
[1] "x is not a character vector"
[1] "length(x) not equal to 3"
[1] "Path 'asdf' does not exist"

assertthat documentation built on May 1, 2019, 10:25 p.m.