with_msg_sink: Run code with a temporary message sink

View source: R/msg.R

with_msg_sinkR Documentation

Run code with a temporary message sink

Description

Sets sink for the duration of code, restoring the previous sink on exit (including on error). Useful in tests and for short-lived capture.

Usage

with_msg_sink(sink, code)

Arguments

sink

Sink function or NULL.

code

Code to run.

Value

The value returned by code.

Author(s)

EDG

See Also

set_msg_sink(), get_msg_sink().

Examples

captured <- list()
with_msg_sink(
  function(m) captured[[length(captured) + 1L]] <<- m,
  {
    # any msg() / msg0() / msgstart() / msgdone() calls in here are captured
  }
)

rtemis.core documentation built on Sept. 20, 2026, 9:06 a.m.