Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

evaluate_and_highlight

Evaluate code and syntax highlight the results


Description

This function runs code and captures the output using evaluate::evaluate(). It syntax highlights code with highlight(), and combines all results into a single HTML div.

Usage

evaluate_and_highlight(
  code,
  fig_save,
  classes = downlit::classes_pandoc(),
  env = NULL
)

Arguments

code

Code to evaluate (as a string).

fig_save

A function with arguments plot and id that is responsible for saving plot to a file (using id to disambiguate multiple plots in the same chunk). It should return a list with components path, width, and height.

classes

A mapping between token names and CSS class names. Bundled classes_pandoc() and classes_chroma() provide mappings that (roughly) match Pandoc and chroma (used by hugo) classes so you can use existing themes.

env

Environment in which to evaluate code; if not supplied, defaults to a child of the global environment.

Value

An string containing HTML.

Examples

evaluate_and_highlight("1 + 2")

downlit

Syntax Highlighting and Automatic Linking

v0.2.1
MIT + file LICENSE
Authors
Hadley Wickham [aut, cre], RStudio [cph]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.