R/quiet.R

Defines functions quiet

Documented in quiet

#' @title Quiet Output
#' @description 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
#' @return Used for its side effects.
#' @author
#' Adapted from \url{https://gist.github.com/daattali/6ab55aee6b50e8929d89}
#' @examples quiet(1 + 1)
#' @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)
    }
}

Try the microbiome package in your browser

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

microbiome documentation built on Nov. 8, 2020, 5:08 p.m.