dot-silenceF: Silencing Functions

Description Usage Arguments Value Examples

Description

Generates a wrapper function that silences the output, messages, and/or warnings of a given function.

Usage

1
  .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:

  • 0: nothing silenced;

  • 1: stdout;

  • 2: stderr messages;

  • 4: stderr warnings.

For example, level 3 = 2 + 1 means silencing stdout and stderr, while 5 = 3 + 2 means silencing stderr messages and warnings, but not outputs to stdout. The default value is 7 = 4 + 2 + 1, which silences all output.

Negative values are supported and mean "silence everything except the corresponding type", e.g., level = -1 silences all except stdout (computed as the binary complementary of 7, i.e. 7 - 1 = 5 = 3 + 2). See examples.

Value

a function

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
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()

pkgmaker documentation built on May 2, 2019, 4:42 p.m.