Skip to content

Instantly share code, notes, and snippets.

@daattali
Created September 25, 2015 00:35
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daattali/6ab55aee6b50e8929d89 to your computer and use it in GitHub Desktop.
Save daattali/6ab55aee6b50e8929d89 to your computer and use it in GitHub Desktop.
Suppress all output from an expression, cross-platform
#' Suppress all output from an expression. Works cross-platform.
#' @param expr Expression to run.
#' @param all If \code{TRUE} then suppress warnings and messages as well;
#' otherwise, only suppress printed output (such as from \code{print} or
#' \code{cat}).
#' @keywords internal
#' @export
quiet <- function(expr, all = TRUE) {
if (Sys.info()['sysname'] == "Windows") {
file <- "NUL"
} else {
file <- "/dev/null"
}
if (all) {
suppressWarnings(suppressMessages(suppressPackageStartupMessages(
capture.output(expr, file = file)
)))
} else {
capture.output(expr, file = file)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment