shush: Suppress all console printing (cat, print, warning, message)

View source: R/r_tools.R

shushR Documentation

Suppress all console printing (cat, print, warning, message)

Description

Sometimes developers leave debugging messages in their packages or, infuriatingly, choose to output messages by using print() or cat() instead of message() or warning() like they're supposed to. This function suppresses them to remove that clutter.

Usage

shush(x)

Arguments

x

(Expression) An expression, usually a call to a function.

Details

If you want to catch errors easily, I recommend possibly() or safely() or quietly() in the purrr package.

Value

The returned value of the expression.

Authors

Source

https://stackoverflow.com/a/48503375/5578429

Examples

loud_mean <- function(x) {
    print("This is from print().")
    cat("This is from cat().\n")
    message("This is from message().")
    warning("This is from warning().")
    mean(x)
}

loud_mean(1:100)

#> [1] "This is from print()."
#> This is from cat().
#> This is from message().
#> [1] 50.5
#> Warning message:
#>     In loud_mean(1:100) : This is from warning().

shush(loud_mean(1:100))

#> [1] 50.5

# magrittr pipelines will also work.
# shush(loud_mean(1:100) %>% sqrt())
#> [1] 7.106335


DesiQuintans/desiderata documentation built on April 9, 2023, 5:43 a.m.