R/silence.R

Defines functions silence

Documented in silence

#' Silences a chunk of code
#'
#' Used as a wrapper to a function, loop, or chunk of code it suppresses any printing
#'
#' @export
#'
#' @param code Chuck of code to be silenced
#' @examples
#' print("hello")
#' silence(print("hello"))
#'

silence <- function(code){

  if(.Platform$OS.type == "windows"){
    # if working with a Windows machine
    sink("NUL")
  } else if (.Platform$OS.type == "unix"){
    # if working on Unix OS
    sink("/dev/null")
  } else {warning("Unknown OS")}

  # running code
    tmp = code
  # restoring sink
    sink()
  # returning function output
    return(tmp)

}
victoria-ramirez/expanded_slf documentation built on July 1, 2020, 12:15 a.m.