shush | R Documentation |
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.
shush(x)
x |
(Expression) An expression, usually a call to a function. |
If you want to catch errors easily, I recommend possibly()
or safely()
or
quietly()
in the purrr
package.
The returned value of the expression.
Desi Quintans (http://www.desiquintans.com)
hplieninger (https://stackoverflow.com/users/2563804/hplieninger)
https://stackoverflow.com/a/48503375/5578429
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
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.