Learn R Programming

formatR (version 0.2-4)

tidy.eval: Evaluate the R code and mask the output by a prefix

Description

This function is designed to insert the output of each chunk of R code into the source code without really breaking the source code, since the output is masked in comments.

Usage

tidy.eval(source = "clipboard", ..., file = "", prefix = "## ")

Arguments

source
the input filename (by default the clipboard; see tidy.source)
...
other arguments passed to tidy.source
file
the file to write by cat; by default the output is printed on screen
prefix
the prefix to mask the output

Value

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

Examples

Run this code
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(source = file.path(system.file(package = "stats"), 
    "demo", "nlm.R"), keep.blank.line = TRUE)

Run the code above in your browser using DataLab