Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/krlmlr/tee

Log all process output to a file, for R
https://github.com/krlmlr/tee

logging r

Last synced: about 1 month ago
JSON representation

Log all process output to a file, for R

Awesome Lists containing this project

README

        

---
output: github_document
---

```{r setup, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# 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*](https://github.com/r-lib/callr) and [*processx*](https://github.com/r-lib/processx). All systems where these packages work (including Windows) are supported.

Works for me.

## Installation

You can install *tee* from GitHub:

``` r
# 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.

```{r example}
library(tee)
ret <- r_tee(function() { print("Hi!"); 42 }, tee = "log/hi.log")
ret
readLines("log/hi.log")
```

```{r cleanup, include = FALSE}
unlink("log", recursive = TRUE)
```

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