Learn R Programming

testit (version 0.14)

has_warning: Check if an R expression produces warnings or errors

Description

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

Usage

has_warning(expr)

has_error(expr, silent = !interactive())

Value

A logical value.

Arguments

expr

an R expression

silent

logical: should the report of error messages be suppressed?

Examples

Run this code
has_warning(1 + 1)
has_warning(1:2 + 1:3)

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

Run the code above in your browser using DataLab