assertive.types (version 0.0-3)

assert_is_try_error: Is the input a condition?

Description

Checks to see if the input is a message, warning or error.

Usage

assert_is_try_error(x, severity = getOption("assertive.severity", "stop"))
assert_is_simple_error(x, severity = getOption("assertive.severity", "stop"))
assert_is_error(x, severity = getOption("assertive.severity", "stop"))
assert_is_simple_warning(x, severity = getOption("assertive.severity", "stop"))
assert_is_warning(x, severity = getOption("assertive.severity", "stop"))
assert_is_simple_message(x, severity = getOption("assertive.severity", "stop"))
assert_is_message(x, severity = getOption("assertive.severity", "stop"))
assert_is_condition(x, severity = getOption("assertive.severity", "stop"))
is_try_error(x, .xname = get_name_in_parent(x))
is_simple_error(x, .xname = get_name_in_parent(x))
is_error(x, .xname = get_name_in_parent(x))
is_simple_warning(x, .xname = get_name_in_parent(x))
is_warning(x, .xname = get_name_in_parent(x))
is_simple_message(x, .xname = get_name_in_parent(x))
is_message(x, .xname = get_name_in_parent(x))
is_condition(x, .xname = get_name_in_parent(x))

Arguments

x
Input to check.
severity
How severe should the consequences of the assertion be? Either "stop", "warning", "message", or "none".
.xname
Not intended to be used directly.

Value

The is_* functions return TRUE or FALSE depending upon whether or not the input is a datetime object.The assert_* functions return nothing but throw an error if the corresponding is_* function returns FALSE.

Examples

Run this code
# stop returns simpleErrors, unless wrapped in a call to try
simple_err <- tryCatch(stop("!!!"), error = function(e) e)
is_simple_error(simple_err)
try_err <- try(stop("!!!"))
is_try_error(try_err)

# is_error checks for both error types
is_error(try_err)
is_error(simple_err)

# warning returns simpleWarnings
simple_warn <- tryCatch(warning("!!!"), warning = function(w) w)
is_simple_warning(simple_warn)
is_warning(simple_warn)

# message returns simpleMessages
simple_msg <- tryCatch(message("!!!"), message = function(m) m)
is_simple_message(simple_msg)
is_message(simple_msg)

# These examples should fail.
assertive.base::dont_stop(assert_is_simple_error(try_err))
assertive.base::dont_stop(assert_is_try_error(simple_err))

Run the code above in your browser using DataCamp Workspace