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

output_hooks

Set or get output hooks for different output formats


Description

The render_*() functions set built-in output hooks for LaTeX, HTML, Markdown, reStructuredText, AsciiDoc, and Textile. The hooks_*() functions return a list of the output hooks for the corresponding format.

Usage

render_html()

hooks_html()

render_asciidoc()

hooks_asciidoc()

render_latex()

hooks_latex()

render_sweave()

hooks_sweave(envirs = c("Sinput", "Soutput", "Schunk"))

render_listings()

hooks_listings(envirs = c("Sinput", "Soutput", "Schunk"))

render_markdown(strict = FALSE, fence_char = "`")

hooks_markdown(strict = FALSE, fence_char = "`")

render_jekyll(highlight = c("pygments", "prettify", "none"), extra = "")

hooks_jekyll(highlight = c("pygments", "prettify", "none"), extra = "")

render_rst(strict = FALSE)

hooks_rst(strict = FALSE)

render_textile()

hooks_textile()

Arguments

envirs

Names of LaTeX environments for code input, output, and chunk.

strict

Boolean; whether to use strict markdown or reST syntax. For markdown, if TRUE, code blocks will be indented by 4 spaces, otherwise they are put in fences made by three backticks. For reST, if TRUE, code is put under two colons and indented by 4 spaces, otherwise it is put under the sourcecode directive (this is useful for e.g. Sphinx).

fence_char

A single character to be used in the code blocks fence. This can be e.g. a backtick or a tilde, depending on your Markdown rendering engine.

highlight

Which code highlighting engine to use: if pygments, the Liquid syntax is used (default approach Jekyll); if prettify, the output is prepared for the JavaScript library ‘prettify.js’; if none, no highlighting engine will be used, and code blocks are simply indented by 4 spaces).

extra

Extra tags for the highlighting engine. For pygments, this can be 'linenos'; for prettify, it can be 'linenums'.

Details

There are three variants of Markdown documents: ordinary Markdown (render_markdown(strict = TRUE), which calls hooks_markdown(strict = TRUE)), extended Markdown (e.g., GitHub Flavored Markdown and Pandoc; render_markdown(strict = FALSE), which calls hooks_markdown(strict = FALSE)), and Jekyll (a blogging system on GitHub; render_jekyll(), which calls hooks_jekyll()).

For LaTeX output, there are three variants: knitr's default style (render_latex(), which calls hooks_latex() and uses the LaTeX framed package), Sweave style (render_sweave(), which calls hooks_sweave() and uses ‘Sweave.sty’), and listings style (render_listings(), which calls hooks_listings() and uses LaTeX listings package).

Default HTML output hooks are set by render_html() (which calls hooks_html()); render_rst() (which calls hooks_rst()) is for reStructuredText; render_textile() (which calls hooks_textile()) is for Textile, and render_asciidoc() (which calls hooks_asciidoc()) is AsciiDoc.

The render_*() functions can be used before knit() or in the first chunk of the input document (ideally this chunk has options include = FALSE and cache = FALSE) so that all the following chunks will be formatted as expected.

You can also use knit_hooks to set the format's hooks with the hooks_*() functions; see references for more info on further customizing output hooks.

Value

NULL for render_* functions; corresponding hooks are set as a side effect. A list of output hooks for hooks_*() functions.

References

Examples

# below is pretty much what knitr::render_markdown() does:
knitr::knit_hooks$set(knitr::hooks_markdown())

# you can retrieve a subset of the hooks and set them, e.g.,
knitr::knit_hooks$set(knitr::hooks_markdown()["source"])

knitr::knit_hooks$restore()

knitr

A General-Purpose Package for Dynamic Report Generation in R

v1.33
GPL
Authors
Yihui Xie [aut, cre] (<https://orcid.org/0000-0003-0645-5666>), Abhraneel Sarma [ctb], Adam Vogt [ctb], Alastair Andrew [ctb], Alex Zvoleff [ctb], Andre Simon [ctb] (the CSS files under inst/themes/ were derived from the Highlight package http://www.andre-simon.de), Aron Atkins [ctb], Aaron Wolen [ctb], Ashley Manton [ctb], Atsushi Yasumoto [ctb] (<https://orcid.org/0000-0002-8335-495X>), Ben Baumer [ctb], Brian Diggs [ctb], Brian Zhang [ctb], Bulat Yapparov [ctb], Cassio Pereira [ctb], Christophe Dervieux [ctb], David Hall [ctb], David Hugh-Jones [ctb], David Robinson [ctb], Doug Hemken [ctb], Duncan Murdoch [ctb], Elio Campitelli [ctb], Ellis Hughes [ctb], Emily Riederer [ctb], Fabian Hirschmann [ctb], Fitch Simeon [ctb], Forest Fang [ctb], Frank E Harrell Jr [ctb] (the Sweavel package at inst/misc/Sweavel.sty), Garrick Aden-Buie [ctb], Gregoire Detrez [ctb], Hadley Wickham [ctb], Hao Zhu [ctb], Heewon Jeon [ctb], Henrik Bengtsson [ctb], Hiroaki Yutani [ctb], Ian Lyttle [ctb], Hodges Daniel [ctb], Jake Burkhead [ctb], James Manton [ctb], Jared Lander [ctb], Jason Punyon [ctb], Javier Luraschi [ctb], Jeff Arnold [ctb], Jenny Bryan [ctb], Jeremy Ashkenas [ctb, cph] (the CSS file at inst/misc/docco-classic.css), Jeremy Stephens [ctb], Jim Hester [ctb], Joe Cheng [ctb], Johannes Ranke [ctb], John Honaker [ctb], John Muschelli [ctb], Jonathan Keane [ctb], JJ Allaire [ctb], Johan Toloe [ctb], Jonathan Sidi [ctb], Joseph Larmarange [ctb], Julien Barnier [ctb], Kaiyin Zhong [ctb], Kamil Slowikowski [ctb], Karl Forner [ctb], Kevin K. Smith [ctb], Kirill Mueller [ctb], Kohske Takahashi [ctb], Lorenz Walthert [ctb], Lucas Gallindo [ctb], Marius Hofert [ctb], Martin Modrák [ctb], Michael Chirico [ctb], Michael Friendly [ctb], Michal Bojanowski [ctb], Michel Kuhlmann [ctb], Miller Patrick [ctb], Nacho Caballero [ctb], Nick Salkowski [ctb], Niels Richard Hansen [ctb], Noam Ross [ctb], Obada Mahdi [ctb], Pavel N. Krivitsky [ctb] (<https://orcid.org/0000-0002-9101-3362>), Qiang Li [ctb], Ramnath Vaidyanathan [ctb], Richard Cotton [ctb], Robert Krzyzanowski [ctb], Romain Francois [ctb], Ruaridh Williamson [ctb], Scott Kostyshak [ctb], Sebastian Meyer [ctb], Sietse Brouwer [ctb], Simon de Bernard [ctb], Sylvain Rousseau [ctb], Taiyun Wei [ctb], Thibaut Assus [ctb], Thibaut Lamadon [ctb], Thomas Leeper [ctb], Tim Mastny [ctb], Tom Torsney-Weir [ctb], Trevor Davis [ctb], Viktoras Veitas [ctb], Weicheng Zhu [ctb], Wush Wu [ctb], Zachary Foster [ctb]
Initial release

We don't support your browser anymore

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