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

  • html_preview is only consulted by reprex_render(), but it is a formal argument of reprex_document() so that it can be included in the YAML frontmatter.

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.

reprex_document(
  venue = c("gh", "r", "rtf", "html", "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,
  html_preview
)

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

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

  • "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" and "rtf".

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 option tidyverse.quiet, which suppresses (TRUE, the default) or includes (FALSE) the startup message for the tidyverse package. 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

html_preview

Logical. Whether to show rendered output in a viewer (RStudio or browser). Always FALSE in a noninteractive session. Read more about opt().

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_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: 0x14ab2a0> #> <environment: namespace:knitr> #> #> #> $knitr$knit_hooks #> NULL #> #> $knitr$opts_hooks #> NULL #> #> $knitr$opts_template #> NULL #> #> #> $pandoc #> $pandoc$to #> [1] "commonmark" #> #> $pandoc$from #> [1] "markdown+autolink_bare_uris+tex_math_single_backslash-implicit_figures" #> #> $pandoc$args #> [1] "--standalone" "--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) #> 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 %in% c("gh", "html"))) #> } #> if (isTRUE(session_info)) { #> input_lines <- c(input_lines, "", si(details = venue %in% #> c("gh", "html"))) #> } #> write_lines(input_lines, knit_input) #> } #> <bytecode: 0x326d4e0> #> <environment: 0x3265d98> #> #> $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: 0x1a796b8> #> <environment: 0x1a739e8> #> #> attr(,"class") #> [1] "rmarkdown_output_format"