Upgrade to Pro — share decks privately, control downloads, hide ads and more …

coRps Seeking Help with reprex

March 22, 2023

coRps Seeking Help with reprex

Our goal today’s coRps session is to explore and develop reproducible examples as a better way to ask for help when you run into a problem with R.


March 22, 2023

More Decks by Aaron

Other Decks in Programming


  1. why reprex? “ https://community.rstudio.com/t/faq-whats-a-reproducible-example-reprex-and-how-do-i-create-one/5219 getting unstuck is hard. your first

    step here is usually to create a reprex, or reproducible example. the goal of a reprex is to package your code, and information about your problem so that others can run it and feel your pain. then, hopefully, folks can more easily provide a solution. curtis kephart | posit
  2. imagine that youʼve made a cake, and for some reason

    itʼs turned out absolutely awful - weʼre talking completely inedible. asking a question without a reprex is like asking, “why didnʼt my cake turn out right?” – there are hundreds of possible answers to that question, and itʼs going to take a long time to narrow in on the exact cause for your inedible cake creation. asking a question with a reprex is like asking, “my cake didnʼt turn out, and hereʼs the recipe I used and the steps that I followed. where did I go wrong?” using this method is going to significantly increase the likelihood of you getting a helpful response, faster! an analogy “ https://www.jessemaegan.com/blog/so-you-ve-been-asked-to-make-a-reprex/ ariel
  3. 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 “ jenny bryan | posit https://speakerdeck.com/jennybc/reprex-help-me-help-you?slide=5
  4. parts of a reproducible example 1. background information - describe

    what you are trying to do. what have you already done? 2. complete set up - include any library() calls and data to reproduce your issue. data for a reprex: here's a discussion on setting up data for a reprex 3. make it run - include the minimal code required to reproduce your error on the data provided. people should be able to copy and paste your code chunk and get the same error. how do I format my text so it has nice code chunks? 4. minimal - strip away everything that is not directly related to your problem. this usually involves creating a much smaller and simpler set of code and data compared to that which created your issue “ https://community.rstudio.com/t/faq-whats-a-reproducible-example-reprex-and-how-do-i-create-one/5219 curtis kephart | posit
  5. ▪ self-contained: everything needed to recreate the issue at hand

    should be contained in the reprex ▪ minimal: use small and/or built-in data (e.g., mtcars), and strip away extraneous code ▪ runnable: a simple copy-paste should be all thatʼs needed to run the reprex, and running it shouldnʼt generate errors except for those that the reprex is intended to exemplify ▪ optional: donʼt force people to run the code in order to understand the issue; include the relevant output/errors as part of the reprex (in a way that doesnʼt disrupt the codeʼs runnability) ▪ reproducible: use seeds for random processes ▪ nonintrusive: donʼt mess with other peopleʼs settings and computer environments (but if you do, [a] be obvious about it and [b] put things back the way they were) a quality reprex is: “ https://data.library.virginia.edu/ask-better-code-questions-and-get-better-answers-with-reprex/ jacob goldstein-greenwood | university of virginia
  6. the problem ““I need to convert a character string representing

    Dec. 1, 2020, into a date object, but when I run the as_date() function in R, the output has the year, month, and date all wrong. Any advice?” Thereʼs no clear starting point for addressing this question. Is the literal character string “Dec. 1, 2020”? Is it “120120”? Could it be “2020-12-01”? And how are the year, month, and date all wrong? Further, unless someone responding to the question happens to recognize that as_date() is from the lubridate package, theyʼre likely to run into entirely avoidable friction as they try to recreate and address the issue. https://data.library.virginia.edu/ask-better-code-questions-and-get-better-answers-with-reprex/ jacob goldstein-greenwood | university of virginia
  7. why reprex? writing a good reprex can seem like a

    hassle but if the asker canʼt be bothered, why should the answer? practice this often and it will make you a better programmer it will increase your knowledge of language “ jenny bryan | posit https://speakerdeck.com/jennybc/reprex-help-me-help-you?slide=21
  8. boiling down your problem into a reproducible example more often

    than not helps you identify the source of the problem
  9. ``` r library(tibble) library(dplyr, warn.conflicts = FALSE) library(lubridate, warn.conflicts =

    FALSE) df <- tibble::tribble( ~appointment_date, ~visit_date, ~value, "4/12/2018", "5/10/2018", 0.473076334, "3/1/2019", "5/10/2018", 0.512464703, "16/11/18", "5/10/2018", 0.277306361) df %>% mutate(appointment_date = mdy(appointment_date), visit_date = mdy(visit_date)) #> Warning: There was 1 warning in `mutate()`. #> ℹ In argument: `appointment_date = mdy(appointment_date)`. #> Caused by warning: …and do more of this
  10. how? utilize - tibble, datapasta, runif(), sample(), built in datasets,

    expand_grid() copy example to clipboard reprex::reprex(venue = “slack”)
  11. additional resources • help me help you: creating reproducible examples

    | rstudio (2018) • reprex • ask better code questions (and get better answers) with reprex • so youʼve been asked to make a reprex • faq: what's a reproducible example (`reprex`) and how do I create one?