R/stfu.R

Defines functions stfu

Documented in stfu

#' Shut the File Up
#'
#' Given an expression, stfu evaluates and returns the value of the expression, but supressesses output to the console.
#'
#' @param expr
#'
#' @return whatever expr should return
#' @export
#'
#' @examples
#' stfu(print('Foo'))
#' stfu(cat('Foo'))
stfu <- function(expr) {
    fileloc <- tempfile()
    sink(fileloc)
    foo <- eval(expr)
    sink(NULL)
    unlink(fileloc)
    return(foo)
}
AABoyles/ShRoud documentation built on May 5, 2019, 11:28 a.m.