tidy_eval: Insert output to source code

View source: R/eval.R

tidy_evalR Documentation

Insert output to source code

Description

Evaluate R code by chunks, then insert the output to each chunk. As the output is masked in comments, the source code will not break.

Usage

tidy_eval(
  source = "clipboard",
  ...,
  file = "",
  prefix = "## ",
  envir = parent.frame()
)

Arguments

source

The input file name (by default the clipboard; see tidy_source()).

...

Other arguments passed to tidy_source().

file

The file name to write to via cat().

prefix

The prefix to mask the output.

envir

The environment in which to evaluate the code. By default the parent frame; set envir = NULL or envir = new.env() to avoid the possibility of contaminating the parent frame.

Value

Evaluated R code with corresponding output (printed on screen or written to a file).

References

https://yihui.org/formatR/

Examples

library(formatR)
## evaluate simple code as a character vector
tidy_eval(text = c("a<-1+1;a", "matrix(rnorm(10),5)"))

## evaluate a file
tidy_eval(system.file("format", "messy.R", package = "formatR"))

formatR documentation built on Jan. 18, 2023, 1:09 a.m.