Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

with_sink

Output redirection


Description

Temporarily divert output to a file via sink(). For sinks of type message, an error is raised if such a sink is already active.

Usage

with_output_sink(new, code, append = FALSE, split = FALSE)

local_output_sink(
  new = list(),
  append = FALSE,
  split = FALSE,
  .local_envir = parent.frame()
)

with_message_sink(new, code, append = FALSE)

local_message_sink(new = list(), append = FALSE, .local_envir = parent.frame())

Arguments

new

[character(1)|connection]
A writable connection or a character string naming the file to write to. Passing NULL will throw an error.

code

[any]
Code to execute in the temporary environment

append

logical. If TRUE, output will be appended to file; otherwise, it will overwrite the contents of file.

split

logical: if TRUE, output will be sent to the new sink and to the current output stream, like the Unix program tee.

.local_envir

[environment]
The environment to use for scoping.

Value

[any]
The results of the evaluation of the code argument.

See Also

withr for examples


withr

Run Code 'With' Temporarily Modified Global State

v2.4.2
MIT + file LICENSE
Authors
Jim Hester [aut, cre], Kirill Müller [aut], Kevin Ushey [aut], Hadley Wickham [aut], Winston Chang [aut], Jennifer Bryan [ctb], Richard Cotton [ctb], RStudio [cph]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.