Skip to content
Render bits of R code for sharing, e.g., on GitHub or StackOverflow.
R CSS
Branch: master
Clone or download
marionlouveaux and jennybc Suppress startup messages: created article (#271)
* Suppress startup messages: init article

Issue #187

* startup messages: add reprex of fake package for tests

#187

* Suppress startup messages: writing article

Issue #187

* Suppress startup messages: corrections

- Adding quick syntax reminder
- Removing the startuppackage
- Revealing chunk code
- Modifying paragraph about tidyverse_quiet

Issue #187

* Suppress startup messages: corrections

- Using package instead of library
- Using attach instead of load
- Removing {} around packages names
- Setting tidyverse_quiet to FALSE
- Adding .Rprofile configuration info

Issue #187

* Rename file

* Shorten title

* Work on the article

* Add NEWS bullet
Latest commit f888a72 Jul 28, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github Add movebot config (#211) Oct 14, 2018
R Tweak examples; fix spelling and words Jul 19, 2019
img Add open graph image Jun 23, 2019
inst Venue "so" is *almost* "gh" now (#257) May 17, 2019
internal Add wrapper to reprex() in a different language or locale (#274) Jul 18, 2019
man Tweak examples; fix spelling and words Jul 19, 2019
pkgdown/favicon Add bigger favicons Dec 6, 2018
slides/2018-09_reprex-rstudio-webinar Photo used in slides Sep 19, 2018
tests Make sure input is UTF-8 ASAP; test latin1 input (#263) May 20, 2019
vignettes Suppress startup messages: created article (#271) Jul 28, 2019
.Rbuildignore Created by use_pkgdown_travis() Dec 6, 2018
.gitignore Stop tracking docs/ Dec 6, 2018
.travis.yml Make it possible to see if tests are being skipped May 17, 2019
DESCRIPTION R 3.1 has fallen off the end Jul 19, 2019
LICENSE Update LICENSE Jan 7, 2018
LICENSE.md De-header the MIT license Apr 5, 2018
NAMESPACE Add wrapper to reprex() in a different language or locale (#274) Jul 18, 2019
NEWS.md Suppress startup messages: created article (#271) Jul 28, 2019
README.md Venue "so" is *almost* "gh" now (#257) May 17, 2019
_pkgdown.yml Modernize _pkgdown.yml Jul 19, 2019
appveyor.yml 3rd attempt to install callr from source Jul 19, 2019
codecov.yml Less draconian coverage thresholds Sep 28, 2017
cran-comments.md Update cran-comments May 16, 2019
reprex.Rproj Update RStudio & roxygen2 May 25, 2017

README.md

reprex

CRAN_Status_Badge Travis-CI Build Status AppVeyor Build Status Coverage status lifecycle

Overview

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, suitable for GitHub or Stack Overflow, 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.

Installation

Install from CRAN:

install.packages("reprex")

or get a development version from GitHub:

devtools::install_github("tidyverse/reprex")

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.

Usage

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

(y <- 1:4)
mean(y)

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

reprex()

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 CommonMark Markdown is ready to be pasted from your clipboard:

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

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

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

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

In addition to GitHub, this markdown also works on Stack Overflow and Discourse. Those venues can be formally requested via venue = "so" and venue = "ds", but they are just aliases for venue = "gh".

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!

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

  • Get html with reprex(..., venue = "html"). Useful for sites that don't support markdown.

  • Prepare rendered, syntax-highlighted code snippets to paste into Keynote or PowerPoint, with reprex(..., venue = "rtf"). This feature is still experimental; see the associated article for more.

  • By default, figures are uploaded to imgur.com and the 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.

  • Append session info via reprex(..., si = TRUE).

  • 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 the reprex project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.

You can’t perform that action at this time.