+ - 0:00:00
Notes for current slide
Notes for next slide

Reproducible examples

INFO 5940
Cornell University

1 / 9

2 / 9

A side-by-side comparison of a monster providing problematic code to tech support when it is on a bunch of crumpled, disorganized papers, with both monsters looking sad and very stressed (left), compared to victorious looking monsters celebrating when code is provided in a nice box with a bow labeled 'reprex'. Title text reads 'reprex: make reproducible examples. Help them help everyone!'

Source: Allison Horst

3 / 9

Reproducible examples

  • reprex (noun)
  • reprex
  • reprex::reprex()
4 / 9

Why reprexes?

Easier to talk about code that:

  • Actually runs
5 / 9

Why reprexes?

Easier to talk about code that:

  • Actually runs

  • I don't have to run

5 / 9

Why reprexes?

Easier to talk about code that:

  • Actually runs

  • I don't have to run

  • I can easily run
5 / 9

reprex

library(tidyverse)
count(diamonds, colour)
6 / 9

Customizing reprex()

reprex(
x = mean(rnorm(100)),
si = TRUE
)
reprex(
x = mean(rnorm(100)),
venue = "r"
)
reprex(
x = {
if (TRUE) "true branch" else {
"else branch"
}
},
style = TRUE
)
7 / 9

Reprex do's and don'ts

  • Ensure the example is fully reproducible
  • Use the smallest, simplest, most built-in data possible
  • Include commands on a strict "need to run" basis
  • Consider including "session info"
  • Use good coding style to ensure the readability of your code by other human beings
  • Ensure portability of the code
8 / 9

Build some reproducible examples

15:00
9 / 9

2 / 9
Paused

Help

Keyboard shortcuts

, , Pg Up, k Go to previous slide
, , Pg Dn, Space, j Go to next slide
Home Go to first slide
End Go to last slide
Number + Return Go to specific slide
b / m / f Toggle blackout / mirrored / fullscreen mode
c Clone slideshow
p Toggle presenter mode
t Restart the presentation timer
?, h Toggle this help
Esc Back to slideshow