.silenceF {pkgmaker} | R Documentation |
Silencing Functions
Description
Generates a wrapper function that silences the output, messages, and/or warnings of a given function.
Usage
.silenceF(f, level = 7L)
Arguments
f |
function to silence |
level |
a single numeric (integer) that indicates the silencing level, which encodes the set of output to be silenced. It is interpreted like unix permission bit system, where each bit of the binary expression of the silencing level corresponds to a given type of output:
For example, level Negative values are supported and mean "silence everything except the corresponding type",
e.g., |
Value
a function
Examples
f <- function(){
cat("stdout message\n")
message("stderr message")
warning("stderr warning", immediate. = TRUE)
}
# example of generated wrapper
g <- .silenceF(f)
g
# use of silencing level
for(l in 7:-7){ message("\nLevel: ", l); .silenceF(f, l)() }
# inline functions
ifun <- .silenceF(function(){ f(); invisible(1) })
ifun()
ifun <- .silenceF(function(){ f(); 1 })
ifun()
ifun <- .silenceF(function(){ f(); 1 }, 2L)
ifun()