reprex v0.2.0


Monthly downloads



Prepare Reproducible Example Code via the Clipboard

Convenience wrapper that uses the 'rmarkdown' package to render small snippets of code to target formats that include both code and output. The goal is to encourage the sharing of small, reproducible, and runnable examples on code-oriented websites, such as <> and <>, or in email. The user's clipboard is the default source of input code and the default target for rendered output. 'reprex' also extracts clean, runnable R code from various common formats, such as copy/paste from an R session.



CRAN\_Status\_Badge Travis-CI Build
Status AppVeyor Build
Status Coverage
status lifecycle

Prepare reprexes for posting to GitHub issues, StackOverflow, or Slack snippets. What is a reprex? It’s a reproducible example, as coined by Romain Francois.

Given R code on the clipboard, selected in RStudio, as an expression (quoted or not), or in a file …

  • run it via rmarkdown::render(),
  • with deliberate choices re: arguments and setup chunk.

Get resulting runnable code + output as

  • Markdown, formatted for target venue, e.g. gh or so, or as
  • R code, augmented with commented output.

Result is returned invisibly, placed on the clipboard, and written to a file. Preview an HTML version in RStudio viewer or default browser.


Install from CRAN:


or get a development version from GitHub:


On Linux, you probably want to install xclip or xsel, so reprex can access the X11 clipboard. This is ‘nice to have’, but not mandatory. The usual sudo apt-get install or sudo yum install installation methods should work for both xclip and xsel.


Let’s say you copy this code onto your clipboard:

(y <- 1:4)

Then call reprex(), where the default target venue is GitHub:


A nicely rendered HTML preview will display in RStudio’s Viewer (if you’re in RStudio) or your default browser otherwise.

The relevant bit of GitHub-flavored Markdown is ready to be pasted from your clipboard:

``` r
(y <- 1:4)
#> [1] 1 2 3 4
#> [1] 2.5

Here’s what that Markdown would look like rendered in a GitHub issue:

(y <- 1:4)
#> [1] 1 2 3 4
#> [1] 2.5

Anyone else can copy, paste, and run this immediately.

Instead of reading from the clipboard, you can:

  • reprex(mean(rnorm(10))) to get code from expression.

  • reprex(input = "mean(rnorm(10))\n") gets code from character vector (detected via length or terminating newline). Leading prompts are stripped from input source: reprex(input = "> median(1:3)\n") produces same output as reprex(input = "median(1:3)\n")

  • reprex(input = "my_reprex.R") gets code from file

  • Use one of the RStudio add-ins to use the selected text or current file.

But wait, there’s more!

  • Set the target venue to Stack Overflow with reprex(..., venue = "so").

  • Get a runnable R script, augmented with commented output, with reprex(..., venue = "R"). This is useful for Slack, email, etc.

  • By default, figures are uploaded to and resulting URL is dropped into an inline image tag.

  • Use the outfile argument to control where results are left behind. Use outfile = NA to work in current working directory.

  • Get clean, runnable code from wild-caught reprexes with

    • reprex_invert() = the opposite of reprex()
    • reprex_clean(), e.g. when you copy/paste from GitHub or Stack Overflow
    • reprex_rescue(), when you’re dealing with copy/paste from R Console

Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.

Functions in reprex

Name Description
opt Consult an option, then default
un-reprex Un-render a reprex
reprex_addin Render a reprex
reprex Render a reprex
No Results!

Vignettes of reprex

No Results!

Last month downloads


License MIT + file LICENSE
VignetteBuilder knitr
Encoding UTF-8
LazyData true
SystemRequirements pandoc (>= 1.12.3) -
NeedsCompilation no
Packaged 2018-06-22 04:23:58 UTC; jenny
Repository CRAN
Date/Publication 2018-06-22 23:40:09 UTC

Include our badge in your README