Learn R Programming

reprex (version 2.1.1)

reprex_document: reprex output format

Description

This is an R Markdown output format designed specifically for making "reprexes", typically created via the reprex() function, which ultimately renders the document with reprex_render(). It is a heavily modified version of rmarkdown::md_document(). The arguments have different spheres of influence:

  • venue potentially affects input preparation and reprex_render().

  • Add content to the primary input, prior to rendering:

    • advertise

    • session_info

    • std_out_err (also consulted by reprex_render())

  • Influence knitr package or chunk options:

    • style

    • comment

    • tidyverse_quiet

RStudio users can create new R Markdown documents with the reprex_document() format using built-in templates. Do File > New File > R Markdown ... > From Template and choose one of:

  • reprex (minimal)

  • reprex (lots of features)

Both include knit: reprex::reprex_render in the YAML, which causes the RStudio "Knit" button to use reprex_render(). If you render these documents yourself, you should do same.

Usage

reprex_document(
  venue = c("gh", "r", "rtf", "html", "slack", "so", "ds"),
  advertise = NULL,
  session_info = opt(FALSE),
  style = opt(FALSE),
  comment = opt("#>"),
  tidyverse_quiet = opt(TRUE),
  std_out_err = opt(FALSE),
  pandoc_args = NULL
)

Value

An R Markdown output format to pass to rmarkdown::render().

Arguments

venue

Character. Must be one of the following (case insensitive):

  • "gh" for GitHub-Flavored Markdown, the default

  • "r" for a runnable R script, with commented output interleaved. Also useful for Slack code snippets; select "R" from the "Type" drop-down menu to enjoy nice syntax highlighting.

  • "rtf" for Rich Text Format (not supported for un-reprexing)

  • "html" for an HTML fragment suitable for inclusion in a larger HTML document (not supported for un-reprexing)

  • "slack" for pasting into a Slack message. Optimized for people who opt out of Slack's WYSIWYG interface. Go to Preferences > Advanced > Input options and select "Format messages with markup". (If there is demand for a second Slack venue optimized for use with WYSIWYG, please open an issue to discuss.)

  • "so" for Stack Overflow Markdown. Note: this is just an alias for "gh", since Stack Overflow started to support CommonMark-style fenced code blocks in January 2019.

  • "ds" for Discourse, e.g., forum.posit.co. Note: this is currently just an alias for "gh".

advertise

Logical. Whether to include a footer that describes when and how the reprex was created. If unspecified, the option reprex.advertise is consulted and, if that is not defined, default is TRUE for venues "gh", "html", "so", "ds" and FALSE for "r", "rtf", "slack".

session_info

Logical. Whether to include sessioninfo::session_info(), if available, or sessionInfo() at the end of the reprex. When venue is "gh", the session info is wrapped in a collapsible details tag. Read more about opt().

style

Logical. Whether to set the knitr chunk option tidy = "styler", which re-styles code with the styler package. Read more about opt().

comment

Character. Prefix with which to comment out output, defaults to "#>". Read more about opt().

tidyverse_quiet

Logical. Sets the options tidyverse.quiet and tidymodels.quiet, which suppress (TRUE, the default) or include (FALSE) the startup messages for the tidyverse and tidymodels packages. Read more about opt().

std_out_err

Logical. Whether to append a section for output sent to stdout and stderr by the reprex rendering process. This can be necessary to reveal output if the reprex spawns child processes or system() calls. Note this cannot be properly interleaved with output from the main R process, nor is there any guarantee that the lines from standard output and standard error are in correct chronological order. See callr::r() for more. Read more about opt().

pandoc_args

Additional command line options to pass to pandoc

Examples

Run this code
reprex_document()

Run the code above in your browser using DataLab