quiet: Suppress function messages and Concatenate and Print (cat)

View source: R/util.R

quietR Documentation

Suppress function messages and Concatenate and Print (cat)

Description

This function is used to suppress information printed from external functions that make internal use of link{message} and cat, which provide information in interactive R sessions. For simulations, the session is not interactive, and therefore this type of output should be suppressed. For similar behaviour for suppressing warning messages see suppressWarnings, though use this function carefully as some warnings can be meaningful and unexpected (see link{convertWarnigs} for a more lawful alternative).

Usage

quiet(..., messages = FALSE, cat = FALSE, warnings = TRUE)

Arguments

...

the functional expression to be evaluated

messages

logical; print all messages?

cat

logical; print all concatenate and calls from cat?

warnings

logical; print all warning messages (generally recommended to leave as TRUE; see link{convertWarnigs} for better alternative)

References

Chalmers, R. P., & Adkins, M. C. (2020). Writing Effective and Reliable Monte Carlo Simulations with the SimDesign Package. The Quantitative Methods for Psychology, 16(4), 248-280. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.20982/tqmp.16.4.p248")}

Sigal, M. J., & Chalmers, R. P. (2016). Play it again: Teaching statistics with Monte Carlo simulation. Journal of Statistics Education, 24(3), 136-156. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1080/10691898.2016.1246953")}

Examples

myfun <- function(x){
   message('This function is rather chatty')
   cat("It even prints in different output forms!\n")
   message('And even at different....')
   cat("...times!\n")
   warning('It may even throw warnings, though careful suppressing these!')
   x
}

out <- myfun(1)
out

# tell the function to shhhh
out <- quiet(myfun(1))
out

# suppress messages, cats, and warnings (not recommended)
out2 <- quiet(myfun(2), warnings = FALSE)
out2


philchalmers/SimDesign documentation built on May 10, 2024, 7:21 a.m.