README.md

tee

The goal of tee is to run R code in an isolated session, or arbitrary scripts, and log the output to a file. It is similar to the tee utility, but relies on callr and processx. All systems where these packages work (including Windows) are supported.

Works for me.

Installation

You can install tee from GitHub:

# install.packages("remotes")
remotes::install_local("krlmlr/tee")

Example

The r_tee() function has (almost) the same signature as callr::r() but supports a tee argument of type character. If set, all output will be written to the file(s) specified in the tee argument. Missing directories are created automatically.

library(tee)
ret <- r_tee(function() { print("Hi!"); 42 }, tee = "log/hi.log")
#> Loading required namespace: fansi
#> [1] "Hi!"
ret
#> [1] 42
readLines("log/hi.log")
#> [1] "[1] \"Hi!\""

ANSI escapes will be stripped automatically from the output via fansi::strip_sgr().



krlmlr/tee documentation built on May 5, 2019, 2:42 a.m.