EVOLUTION-MANAGER
Edit File: reprex.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>R: Render a reprex</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="R.css" /> </head><body> <table width="100%" summary="page for reprex {reprex}"><tr><td>reprex {reprex}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Render a reprex</h2> <h3>Description</h3> <p>Run a bit of R code using <code><a href="../../rmarkdown/html/render.html">rmarkdown::render()</a></code> and write the rendered result to user's clipboard. The goal is to make it easy to share a small reproducible example ("reprex"), e.g., in a GitHub issue. Reprex source can be </p> <ul> <li><p> read from clipboard </p> </li> <li><p> read from current selection or active document in RStudio (with <code><a href="reprex_addin.html">reprex_addin()</a></code>) </p> </li> <li><p> provided directly as expression, character vector, or string </p> </li> <li><p> read from file </p> </li></ul> <p>reprex can also be used for syntax highlighting (with or without rendering); see below for more. </p> <h3>Usage</h3> <pre> reprex(x = NULL, input = NULL, outfile = NULL, venue = c("gh", "so", "ds", "r", "rtf", "html"), render = TRUE, advertise = NULL, si = opt(FALSE), style = opt(FALSE), show = opt(TRUE), comment = opt("#>"), tidyverse_quiet = opt(TRUE), std_out_err = opt(FALSE)) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>x</code></td> <td> <p>An expression. If not given, <code>reprex()</code> looks for code in <code>input</code> or on the clipboard, in that order.</p> </td></tr> <tr valign="top"><td><code>input</code></td> <td> <p>Character. If has length one and lacks a terminating newline, interpreted as the path to a file containing reprex code. Otherwise, assumed to hold reprex code as character vector.</p> </td></tr> <tr valign="top"><td><code>outfile</code></td> <td> <p>Optional basename for output files. When <code>NULL</code> (default), reprex writes to temp files below the session temp directory. If <code>outfile = "foo"</code>, expect output files in current working directory, like <code>foo_reprex.R</code>, <code>foo_reprex.md</code>, and, if <code>venue = "r"</code>, <code>foo_rendered.R</code>. If <code>outfile = NA</code>, expect output files in a location and with basename derived from <code>input</code>, if sensible, or in current working directory with basename derived from <code><a href="../../base/html/tempfile.html">tempfile()</a></code> otherwise.</p> </td></tr> <tr valign="top"><td><code>venue</code></td> <td> <p>Character. Must be one of the following (case insensitive): </p> <ul> <li><p> "gh" for <a href="https://github.github.com/gfm/">GitHub-Flavored Markdown</a>, the default </p> </li> <li><p> "so" for <a href="https://stackoverflow.com/editing-help">Stack Overflow Markdown</a> </p> </li> <li><p> "ds" for Discourse, e.g., <a href="https://community.rstudio.com">community.rstudio.com</a>. Note: this is currently just an alias for "gh"! </p> </li> <li><p> "r" for a runnable R script, with commented output interleaved </p> </li> <li><p> "rtf" for <a href="https://en.wikipedia.org/wiki/Rich_Text_Format">Rich Text Format</a> (not supported for un-reprexing) </p> </li> <li><p> "html" for an HTML fragment suitable for inclusion in a larger HTML document (not supported for un-reprexing) </p> </li></ul> </td></tr> <tr valign="top"><td><code>render</code></td> <td> <p>Logical. Whether to call <code><a href="../../rmarkdown/html/render.html">rmarkdown::render()</a></code> on the templated reprex, i.e. whether to actually run the code. Defaults to <code>TRUE</code>. Exists primarily for the sake of internal testing.</p> </td></tr> <tr valign="top"><td><code>advertise</code></td> <td> <p>Logical. Whether to include a footer that describes when and how the reprex was created. If unspecified, the option <code>reprex.advertise</code> is consulted and, if that is not defined, default is <code>TRUE</code> for venues <code>"gh"</code>, <code>"so"</code>, <code>"ds"</code>, <code>"html"</code> and <code>FALSE</code> for <code>"r"</code> and <code>"rtf"</code>.</p> </td></tr> <tr valign="top"><td><code>si</code></td> <td> <p>Logical. Whether to include <code><a href="../../devtools/html/session_info.html">devtools::session_info()</a></code>, if available, or <code><a href="../../utils/html/sessionInfo.html">sessionInfo()</a></code> at the end of the reprex. When <code>venue</code> is "gh" or "ds", the session info is wrapped in a collapsible details tag. Read more about <code><a href="opt.html">opt()</a></code>.</p> </td></tr> <tr valign="top"><td><code>style</code></td> <td> <p>Logical. Whether to style code with <code><a href="../../styler/html/style_text.html">styler::style_text()</a></code>. Read more about <code><a href="opt.html">opt()</a></code>.</p> </td></tr> <tr valign="top"><td><code>show</code></td> <td> <p>Logical. Whether to show rendered output in a viewer (RStudio or browser). Read more about <code><a href="opt.html">opt()</a></code>.</p> </td></tr> <tr valign="top"><td><code>comment</code></td> <td> <p>Character. Prefix with which to comment out output, defaults to <code>"#>"</code>. Read more about <code><a href="opt.html">opt()</a></code>.</p> </td></tr> <tr valign="top"><td><code>tidyverse_quiet</code></td> <td> <p>Logical. Sets the option <code>tidyverse.quiet</code>, which suppresses (<code>TRUE</code>, the default) or includes (<code>FALSE</code>) the startup message for the tidyverse package. Read more about <code><a href="opt.html">opt()</a></code>.</p> </td></tr> <tr valign="top"><td><code>std_out_err</code></td> <td> <p>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 <code>system()</code> 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 <code><a href="../../callr/html/r_safe.html">callr::r_safe()</a></code> for more. Read more about <code><a href="opt.html">opt()</a></code>.</p> </td></tr> </table> <h3>Value</h3> <p>Character vector of rendered reprex, invisibly. </p> <h3>Details</h3> <p>The usual "code + commented output" is returned invisibly, put on the clipboard, and written to file. An HTML preview displays in RStudio's Viewer pane, if available, or in the default browser, otherwise. Leading <code>"> "</code> prompts, are stripped from the input code. Read more at <a href="https://reprex.tidyverse.org/">https://reprex.tidyverse.org/</a>. </p> <p>reprex sets specific <a href="http://yihui.name/knitr/options/">knitr options</a>: </p> <ul> <li><p> Chunk options default to <code>collapse = TRUE</code>, <code>comment = "#>"</code>, <code>error = TRUE</code>. Note that <code>error = TRUE</code>, because a common use case is bug reporting. </p> </li> <li><p> reprex also sets knitr's <code>upload.fun</code>. It defaults to <code><a href="../../knitr/html/imgur_upload.html">knitr::imgur_upload()</a></code> so figures produced by the reprex appear properly on GitHub, Stack Overflow, or Discourse. Note that this function requires the packages httr & xml2 or RCurl & XML, depending on your knitr version. When <code>venue = "r"</code>, <code>upload.fun</code> is set to <code>identity</code>, so that figures remain local. In that case, you may also want to set <code>outfile</code>. You can supplement or override these options with special comments in your code (see examples). </p> </li></ul> <h3>Syntax highlighting</h3> <p>A secondary use case for reprex is to produce syntax highlighted code snippets, with or without rendering, to paste into presentation software, such as Keynote or PowerPoint. Use <code>venue = "rtf"</code>. </p> <p>This feature is experimental and currently rather limited. It probably only works on macOS and requires the installation of the <a href="http://www.andre-simon.de/doku/highlight/en/highlight.php">highlight</a> command line tool, which can be installed via <a href="https://formulae.brew.sh/formula/highlight">homebrew</a>. This venue is discussed in <a href="https://reprex.tidyverse.org/articles/articles/rtf.html">an article</a> </p> <h3>Examples</h3> <pre> ## Not run: # put some code like this on the clipboard # (y <- 1:4) # mean(y) reprex() # provide code as an expression reprex(rbinom(3, size = 10, prob = 0.5)) reprex({y <- 1:4; mean(y)}) reprex({y <- 1:4; mean(y)}, style = TRUE) # note that you can include newlines in those brackets # in fact, that is often a good idea reprex({ x <- 1:4 y <- 2:5 x + y }) ## provide code via character vector reprex(input = c("x <- 1:4", "y <- 2:5", "x + y")) ## if just one line, terminate with '\n' reprex(input = "rnorm(3)\n") ## customize the output comment prefix reprex(rbinom(3, size = 10, prob = 0.5), comment = "#;-)") # override a default chunk option reprex({ #+ setup, include = FALSE knitr::opts_chunk$set(collapse = FALSE) #+ actual-reprex-code (y <- 1:4) median(y) }) # add prose, use general markdown formatting reprex({ #' # A Big Heading #' #' Look at my cute example. I love the #' [reprex](https://github.com/tidyverse/reprex#readme) package! y <- 1:4 mean(y) }, advertise = FALSE) # read reprex from file tmp <- file.path(tempdir(), "foofy.R") writeLines(c("x <- 1:4", "mean(x)"), tmp) reprex(input = tmp) # read from file and write to similarly-named outfiles reprex(input = tmp, outfile = NA) list.files(dirname(tmp), pattern = "foofy") # clean up file.remove(list.files(dirname(tmp), pattern = "foofy", full.names = TRUE)) # write rendered reprex to file tmp <- file.path(tempdir(), "foofy") reprex({ x <- 1:4 y <- 2:5 x + y }, outfile = tmp) list.files(dirname(tmp), pattern = "foofy") # clean up file.remove(list.files(dirname(tmp), pattern = "foofy", full.names = TRUE)) # write reprex to file AND keep figure local too, i.e. don't post to imgur tmp <- file.path(tempdir(), "foofy") reprex({ #+ setup, include = FALSE knitr::opts_knit$set(upload.fun = identity) #+ actual-reprex-code #' Some prose ## regular comment (x <- 1:4) median(x) plot(x) }, outfile = tmp) list.files(dirname(tmp), pattern = "foofy") # clean up unlink( list.files(dirname(tmp), pattern = "foofy", full.names = TRUE), recursive = TRUE ) ## target venue = Stack Overflow ## https://stackoverflow.com/editing-help ret <- reprex({ x <- 1:4 y <- 2:5 x + y }, venue = "so") ret ## target venue = R, also good for email or Slack snippets ret <- reprex({ x <- 1:4 y <- 2:5 x + y }, venue = "R") ret ## target venue = html ret <- reprex({ x <- 1:4 y <- 2:5 x + y }, venue = "html") ret ## include prompt and don't comment the output ## use this when you want to make your code hard to execute :) reprex({ #+ setup, include = FALSE knitr::opts_chunk$set(comment = NA, prompt = TRUE) #+ actual-reprex-code x <- 1:4 y <- 2:5 x + y }) ## leading prompts are stripped from source reprex(input = c("> x <- 1:3", "> median(x)")) ## End(Not run) </pre> <hr /><div style="text-align: center;">[Package <em>reprex</em> version 0.3.0 <a href="00Index.html">Index</a>]</div> </body></html>