has_message: Check if an R expression produces warnings or errors

Description Usage Arguments Value Examples

Description

The two functions has_warning() and has_error() check if an expression produces warnings and errors, respectively.

Usage

1
2
3
has_warning(expr)

has_error(expr, silent = !interactive())

Arguments

expr

an R expression

silent

logical: should the report of error messages be suppressed?

Value

A logical value.

Examples

1
2
3
4
5
6
has_warning(1 + 1)
has_warning(1:2 + 1:3)

has_error(2 - 3)
has_error(1 + "a")
has_error(stop("err"), silent = TRUE)

Example output

[1] FALSE
[1] TRUE
[1] FALSE
[1] TRUE
[1] TRUE

testit documentation built on April 14, 2021, 5:07 p.m.

Related to has_message in testit...