R/quiet.R

Defines functions quiet

Documented in quiet

#' 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
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)
  }
}
emse-p4a-gwu/p4aGrader documentation built on May 16, 2020, 1:43 a.m.