Skip to content

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:

  • 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
)

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. Works best if you opt out of Slack's WYSIWYG interface and, instead, go to Preferences > Advanced and select "Format messages with markup".

  • "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., community.rstudio.com. 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

Value

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

Examples

reprex_document()
#> $knitr
#> $knitr$opts_chunk
#> $knitr$opts_chunk$dev
#> [1] "png"
#> 
#> $knitr$opts_chunk$dpi
#> [1] 96
#> 
#> $knitr$opts_chunk$fig.width
#> [1] 7
#> 
#> $knitr$opts_chunk$fig.height
#> [1] 5
#> 
#> $knitr$opts_chunk$fig.retina
#> NULL
#> 
#> $knitr$opts_chunk$collapse
#> [1] TRUE
#> 
#> $knitr$opts_chunk$error
#> [1] TRUE
#> 
#> $knitr$opts_chunk$comment
#> [1] "#>"
#> 
#> $knitr$opts_chunk$R.options
#> $knitr$opts_chunk$R.options$tidyverse.quiet
#> [1] TRUE
#> 
#> $knitr$opts_chunk$R.options$tidymodels.quiet
#> [1] TRUE
#> 
#> 
#> 
#> $knitr$opts_knit
#> $knitr$opts_knit$upload.fun
#> function (file, key = "9f3460e67f308f6") 
#> {
#>     if (!is.character(key)) 
#>         stop("The Imgur API Key must be a character string!")
#>     resp = httr::POST("https://api.imgur.com/3/image.xml", config = httr::add_headers(Authorization = paste("Client-ID", 
#>         key)), body = list(image = httr::upload_file(file)))
#>     httr::stop_for_status(resp, "upload to imgur")
#>     res = httr::content(resp, as = "raw")
#>     res = if (length(res)) 
#>         xml2::as_list(xml2::read_xml(res))
#>     if (packageVersion("xml2") >= "1.2.0") 
#>         res <- res[[1L]]
#>     if (is.null(res$link[[1]])) 
#>         stop("failed to upload ", file)
#>     structure(res$link[[1]], XML = res)
#> }
#> <bytecode: 0x56511512eb78>
#> <environment: namespace:knitr>
#> 
#> 
#> $knitr$knit_hooks
#> NULL
#> 
#> $knitr$opts_hooks
#> NULL
#> 
#> $knitr$opts_template
#> NULL
#> 
#> 
#> $pandoc
#> $pandoc$to
#> [1] "gfm-yaml_metadata_block"
#> 
#> $pandoc$from
#> [1] "markdown+autolink_bare_uris+tex_math_single_backslash-implicit_figures"
#> 
#> $pandoc$args
#> [1] "--wrap=preserve"
#> 
#> $pandoc$keep_tex
#> [1] FALSE
#> 
#> $pandoc$latex_engine
#> [1] "pdflatex"
#> 
#> $pandoc$ext
#> [1] ".md"
#> 
#> 
#> $keep_md
#> [1] FALSE
#> 
#> $clean_supporting
#> [1] FALSE
#> 
#> $df_print
#> [1] "default"
#> 
#> $pre_knit
#> function (input, ...) 
#> {
#>     knit_input <- sub("[.]R$", ".spin.Rmd", input)
#>     input_lines <- read_lines(knit_input)
#>     input_lines <- c(rprofile_alert(venue), "", input_lines)
#>     input_lines <- c(reprex_opts(venue), "", input_lines)
#>     if (isTRUE(advertise)) {
#>         input_lines <- c(input_lines, "", ad(venue))
#>     }
#>     if (isTRUE(std_out_err)) {
#>         input_lines <- c(input_lines, "", std_out_err_stub(input, 
#>             venue))
#>     }
#>     if (isTRUE(session_info)) {
#>         input_lines <- c(input_lines, "", si(venue))
#>     }
#>     write_lines(input_lines, knit_input)
#> }
#> <bytecode: 0x565113cf5850>
#> <environment: 0x565113cf9428>
#> 
#> $post_knit
#> NULL
#> 
#> $pre_processor
#> NULL
#> 
#> $intermediates_generator
#> NULL
#> 
#> $post_processor
#> NULL
#> 
#> $on_exit
#> function () 
#> {
#>     if (is.function(base)) 
#>         base()
#>     if (is.function(overlay)) 
#>         overlay()
#> }
#> <bytecode: 0x5651151caef8>
#> <environment: 0x5651151ce0a0>
#> 
#> attr(,"class")
#> [1] "rmarkdown_output_format"