withSink: Execute an expression while redirecting output to a file

View source: R/server.R

withSinkR Documentation

Execute an expression while redirecting output to a file

Description

Execute an expression while redirecting output to a file

Usage

withSink(expr, logfile = tempfile(fileext = ".txt"))

Arguments

expr

The expression to execute

logfile

The file to redirect output to. Default is "tmp.txt".

Value

The result of the expression

Examples

logfile <- tempfile(fileext = ".txt")
withSink(logfile = logfile, expr = {
  cat("Helloworld\n")
  message("Goodbye")
})
readLines(logfile) == c("Helloworld", "Goodbye")

FastRet documentation built on June 25, 2024, 5:07 p.m.