Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/krlmlr/tee
- Owner: krlmlr
- Created: 2018-04-06T11:23:52.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-04-06T12:52:04.000Z (over 6 years ago)
- Last Synced: 2024-10-05T06:27:32.735Z (about 2 months ago)
- Topics: logging, r
- Language: R
- Size: 12.7 KB
- Stars: 9
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.Rmd
- Changelog: NEWS.md
Awesome Lists containing this project
- jimsghstars - krlmlr/tee - Log all process output to a file, for R (R)
README
---
output: github_document
---```{r setup, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# teeThe 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()`.