powered by
Execute an expression while redirecting output to a file
withSink(expr, logfile = tempfile(fileext = ".txt"))
The result of the expression
The expression to execute
The file to redirect output to. Default is "tmp.txt".
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