class: center, middle, inverse, title-slide # make a reprex…… please ## 👋
@sharlagelfand
### ### make-a-reprex-please.netlify.app --- class: middle, center ## your code will eventually break ## you will look for help --- class: middle, center <div class="figure"> <img src="images/xkcd.png" alt="Source: https://xkcd.com/979/" width="647" /> <p class="caption">Source: https://xkcd.com/979/</p> </div> --- class: middle, center ## you will have to ask for help ## you will have to send someone your code --- ```r library(dplyr) mtcars %>% filter(cyl = 6) ``` ``` ## Error: Problem with `filter()` input `..1`. ## x Input `..1` is named. ## ℹ This usually means that you've used `=` instead of `==`. ## ℹ Did you mean `cyl == 6`? ``` --- ```r library(dplyr) # Why does this return no records?! dogs %>% filter(is_cute) ``` ``` ## # A tibble: 0 x 1 ## # … with 1 variable: is_cute <lgl> ``` --- ```r library(dplyr) library(ggplot2) library(readxl) library(tidytext) library(janitor) library(lubridate) # Read data setwd("/Users/sharla/Documents/my_work_folder/project_1/data") data <- read_xlsx("Export 2021-01-02 V5.xlsx") # Clean data data <- data %>% clean_names() # Make names look nice # Add year data %>% mutate(year = case_when(date <= "2020-12-31" & date >= "2020-01-01" ~ 2020, is.na(date) ~ NA)) ``` ``` ## Error: Problem with `mutate()` input `year`. ## x must be a double vector, not a logical vector. ## ℹ Input `year` is `case_when(...)`. ``` --- class: middle, center <img src="images/code-screenshot.png" width="80%" /> --- class: middle, center <img src="images/code-photo.jpg" width="80%" /> --- class: middle, center <img src="images/yihui-1.png" width="80%" /> --- class: middle, center <img src="images/yihui-2.png" width="80%" /> --- class: middle, center <img src="images/yihui-3.png" width="80%" /> --- <img src="images/please-create-a-reprex.png" width="3331" /> --- class: middle, center, inverse # "reproducible example" --- class: middle, inverse ### "If you need help getting unstuck, the first step is to create a reprex, or reproducible example. The goal of a reprex is to package your problematic code in such a way that other people can run it and feel your pain. Then, hopefully, they can provide a solution and put you out of your misery." https://www.tidyverse.org/help/ --- class: middle, inverse ### "If you need help getting unstuck, the first step is to create a reprex, or reproducible example. The goal of a reprex is to package your problematic code in such a way that other people can run it and feel your pain. Then, hopefully, <mark>they can provide a solution and put you out of your misery.</mark>" https://www.tidyverse.org/help/ --- class: middle, inverse ### "If you need help getting unstuck, the first step is to create a reprex, or reproducible example. The goal of a reprex is to package your problematic code in such a way that <mark>other people can run it and feel your pain</mark>. Then, hopefully, they can provide a solution and put you out of your misery." https://www.tidyverse.org/help/ --- class: middle, center # "other people can run it" --- class: middle, center <img src="images/download-a-car.jpg" width="80%" /> --- class: middle, center <img src="images/run-a-screenshot.png" width="80%" /> --- class: middle, center ## ☝ libraries ## ✌ code ## 👌 data --- ```r library(dplyr) library(ggplot2) library(readxl) library(tidytext) library(janitor) library(lubridate) # Read data setwd("/Users/sharla/Documents/my_work_folder/project_1/data") data <- read_xlsx("Export 2021-01-02 V5.xlsx") # Clean data data <- data %>% clean_names() # Make names look nice # Add year data %>% mutate(year = case_when(date <= "2020-12-31" & date >= "2020-01-01" ~ 2020, is.na(date) ~ NA)) ``` ``` ## Error: Problem with `mutate()` input `year`. ## x must be a double vector, not a logical vector. ## ℹ Input `year` is `case_when(...)`. ``` --- ```r *library(dplyr) library(ggplot2) *library(readxl) library(tidytext) library(janitor) library(lubridate) # Read data *setwd("/Users/sharla/Documents/my_work_folder/project_1/data") *data <- read_xlsx("Export 2021-01-02 V5.xlsx") # Clean data data <- data %>% clean_names() # Make names look nice # Add year *data %>% * mutate(year = case_when(date <= "2020-12-31" & date >= "2020-01-01" ~ 2020, * is.na(date) ~ NA)) ``` ``` ## Error: Problem with `mutate()` input `year`. ## x must be a double vector, not a logical vector. ## ℹ Input `year` is `case_when(...)`. ``` --- ```r library(dplyr) library(readxl) setwd("/Users/sharla/Documents/my_work_folder/project_1/data") data <- read_xlsx("Export 2021-01-02 V5.xlsx") data %>% mutate(year = case_when(date <= "2020-12-31" & date >= "2020-01-01" ~ 2020, is.na(date) ~ NA)) ``` ``` ## Error: Problem with `mutate()` input `year`. ## x must be a double vector, not a logical vector. ## ℹ Input `year` is `case_when(...)`. ``` --- ## what if i don't know what code to include? -- ### add one line until it breaks -- ### remove one line until it works... then add back the broken line --- ```r library(dplyr) library(readxl) *setwd("/Users/sharla/Documents/my_work_folder/project_1/data") *data <- read_xlsx("Export 2021-01-02 V5.xlsx") data %>% mutate(year = case_when(date <= "2020-12-31" & date >= "2020-01-01" ~ 2020, is.na(date) ~ NA)) ``` --- class: middle <img src="images/no_csv.png" width="2877" /> --- ## make fake data inline .pull-left[ ```r library(dplyr) tibble(x = c(1, 2), y = c(2, 4)) ``` ``` ## # A tibble: 2 x 2 ## x y ## <dbl> <dbl> ## 1 1 2 ## 2 2 4 ``` ] -- .pull-right[ ```r tribble( ~x, ~y, 1, 2, 2, 4 ) ``` ``` ## # A tibble: 2 x 2 ## x y ## <dbl> <dbl> ## 1 1 2 ## 2 2 4 ``` ] --- ```r library(dplyr) library(readxl) setwd("/Users/sharla/Documents/my_work_folder/project_1/data") data <- read_xlsx("Export 2021-01-02 V5.xlsx") data %>% mutate(year = case_when(date <= "2020-12-31" & date >= "2020-01-01" ~ 2020, is.na(date) ~ NA)) ``` ``` ## Error: Problem with `mutate()` input `year`. ## x must be a double vector, not a logical vector. ## ℹ Input `year` is `case_when(...)`. ``` --- ```r library(dplyr) tibble(date = "2020-01-01") %>% mutate(year = case_when( date <= "2020-12-31" & date >= "2020-01-01" ~ 2020, is.na(date) ~ NA )) ``` ``` ## Error: Problem with `mutate()` input `year`. ## x must be a double vector, not a logical vector. ## ℹ Input `year` is `case_when(...)`. ``` --- class: middle, center # "and feel your pain" ### people are better at understanding output than you'd expect --- class: middle, center, inverse # but how? --- class: center # `reprex` package .pull-left[ ### 🪐 isolated ### 🤝 code + output ### 🏦 different venues ### 🖼 images ] .pull-right[ <img src="images/reprex.svg" width="60%" /> [github.com/tidyverse/reprex](https://github.com/tidyverse/reprex) ] --- class: center, middle, inverse # more live coding ### for later: [code](https://github.com/sharlagelfand/reprex-talk/blob/main/reprex_code.r) and [issues](https://github.com/sharlagelfand/reprex-talk/issues) --- class: middle, center ## you will feel great <img src="images/shel-kariuki.png" width="80%" /> --- class: middle, center ## the odds of someone helping you increase by 1000% ### (please do not try to reproduce my findings) --- class: middle, center ## but you might not even need to ask for help <img src="images/stephen-turner.png" width="80%" /> <img src="images/rika-gorn.png" width="80%" /> ??? it's common to solve your problem through the act of creating the reprex --- class: middle, center <div class="figure"> <img src="images/asking-for-help.png" alt="Shannon Pileggi for @WeAreRLadies" width="80%" /> <p class="caption">Shannon Pileggi for @WeAreRLadies</p> </div> --- class: middle, center .left-column[ ### actually useful resources [rstudio community: how to do a minimal reprex for beginners](https://community.rstudio.com/t/faq-how-to-do-a-minimal-reproducible-example-reprex-for-beginners/23061) [stack overflow: how to make a great R reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) [tidyverse: getting help](https://www.tidyverse.org/help/) ] .right-column[ <div class="figure"> <img src="images/reprex.png" alt="Artwork by @allison_horst" width="90%" /> <p class="caption">Artwork by @allison_horst</p> </div> ]