R/suppressAll.R

Defines functions suppressAll

Documented in suppressAll

#' Suppresses all output except for errors.
#' 
#' Evaluates an expression and suppresses all output except for errors, 
#' meaning: prints, messages, warnings and package startup messages.
#' 
#' @param expr [valid R expression]\cr
#'   Expression. 
#' @return Return value of expression invisibly. 
#' @export 
#' @examples
#' suppressAll({
#'   print("foo")
#'   message("foo")
#'   warning("foo")
#' })
suppressAll = function(expr) {
  capture.output({
    z = suppressWarnings(
      suppressMessages(
        suppressPackageStartupMessages(force(expr))                  
      )
    )
  })
  invisible(z)
}

Try the BBmisc package in your browser

Any scripts or data that you put into this service are public.

BBmisc documentation built on Sept. 29, 2022, 5:12 p.m.