Learn R Programming

FastRet (version 1.3.0)

withSink: 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"))

Value

The result of the expression

Arguments

expr

The expression to execute

logfile

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

Examples

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

Run the code above in your browser using DataLab