pkgcond (version 0.1.0)

suppress: Selectively suppress warnings and messages

Description

This collection of functions allow the suppression of condition messages, warnings and messages, through filtering the condition message, the condition class or a combination of the two.

Usage

suppress_conditions(expr, pattern = NULL, class = NULL, ...)

suppress_warnings(expr, pattern = NULL, class = "warning", ...)

suppress_messages(expr, pattern = NULL, class = "message", ...)

Arguments

expr

An expression to evaluate.

pattern

A regular expression pattern to match on.

class

The class or classes that you would like to filter. When more that one is given the condition may match any of the classes.

...

Arguments passed on to base::grepl

pattern

character string containing a regular expression (or character string for fixed = TRUE) to be matched in the given character vector. Coerced by as.character to a character string if possible. If a character vector of length 2 or more is supplied, the first element is used with a warning. Missing values are allowed except for regexpr and gregexpr.

x

a character vector where matches are sought, or an object which can be coerced by as.character to a character vector. Long vectors are supported.

ignore.case

if FALSE, the pattern matching is case sensitive and if TRUE, case is ignored during matching.

perl

logical. Should Perl-compatible regexps be used?

fixed

logical. If TRUE, pattern is a string to be matched as is. Overrides all conflicting arguments.

useBytes

logical. If TRUE the matching is done byte-by-byte rather than character-by-character. See ‘Details’.

Functions

  • suppress_conditions: The general case of suppressing both messages and warnings.

  • suppress_warnings: A convenience wrapper that specifies warning class to suppress.

  • suppress_messages: A convenience wrapper that specifies warning class to suppress.

Examples

Run this code
# NOT RUN {
testit <- function(){
    warning("this function does nothing.")
    warning("it's pretty useless.")
}
suppress_warning(testit(), "useless")  # Will suppress only the second warning by pattern


# If my_pkg used pkgcond for conditions,
# This would suppress all messages and warnings originating
# in my_pkg functions.
suppress_conditions(my_function(), class='my_pkg-condition')
# }

Run the code above in your browser using DataLab