Slide 1

Slide 1 text

  Jennifer Bryan 
 RStudio, University of British Columbia @JennyBryan @jennybc reprex: the package, the point

Slide 2

Slide 2 text

How to ask questions so they get answered! Possibly by yourself! 2017 March 07 w/ James (JD) Long, Jenny Bryan, Scott Chamberlain an rOpenSci Community call: https://github.com/ropensci/commcalls/issues/14 Collaborative notes: http://bit.ly/commcallv13

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

http://stat545.com 300-500 GitHub issue comments by me Sept-Nov each year

Slide 5

Slide 5 text

conversations about code are more productive when they contain code code that actually runs code that I don’t have to run code that I can easily run

Slide 6

Slide 6 text

https://github.com/jennybc/reprex http://jennybc.github.io/reprex/

Slide 7

Slide 7 text

install.packages("reprex") ## or devtools::install_github("jennybc/reprex")

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

code that actually runs code is run in separate, fresh R session ergo, it must be self-contained! must load all necessary packages must create all necessary objects

Slide 10

Slide 10 text

not self-contained — forgot to load necessary package not self-contained — forgot to define template YAAAASSSSSS

Slide 11

Slide 11 text

code that I don’t have to run did I mention: I touch 300 - 500 issues/course? I can often get the point w/o running code IFF I can see the output SHOW ME SOME OUTPUT, not just the code

Slide 12

Slide 12 text

No content

Slide 13

Slide 13 text

code that I can easily run do not copy/paste your R transcript do not take a screenshot of your R session must I edit out the prompts? must I comment the output? HELP ME HELP YOU

Slide 14

Slide 14 text

> library(purrr) > x <- list(one = list(always = "a", sometimes = "b"), + two = list(always = "b", sometimes = NULL)) > x %>% map_chr("always") one two "a" "b" > x %>% map_chr("sometimes") Error: Result 2 is not a length 1 atomic vector

Slide 15

Slide 15 text

library(purrr) x <- list(one = list(always = "a", sometimes = "b"), two = list(always = "b", sometimes = NULL)) x %>% map_chr("always") #> one two #> "a" "b" x %>% map_chr("sometimes") #> Error: Result 2 is not a length 1 atomic vector

Slide 16

Slide 16 text

live demo

Slide 17

Slide 17 text

basic copy + reprex() copy + add-in select or focus + add-in venue = “so”, venue= “R” si = TRUE input, outfile include a figure reprex_invert() reprex_clean() reprex_rescue() stuff I hope to show

Slide 18

Slide 18 text

Why make a reprex?

Slide 19

Slide 19 text

1. get help 2. bug report

Slide 20

Slide 20 text

https://github.com/jennybc/reprex#what-is-a-reprex

Slide 21

Slide 21 text

writing a good reprex can seem like a hassle but if asker can’t be bothered, why should the answerer? practice this often and it will make you a better programmer it will increase your knowledge of the language

Slide 22

Slide 22 text

writing a reprex helps you ambush your problem from behind “demonstrate my problem in a small example” sounds so much more doable than “figure out how my code is borked” > x% of the time I solve my own problem, but the reprex mentality is enabling

Slide 23

Slide 23 text

No content