class: center, middle, title-slide .title[ # When Things Don’t Work: Some Debugging Tips ] .author[ ### Luke Tierney ] .institute[ ### University of Iowa ] .date[ ### 2025-01-17 ] --- Sometimes code you write doesn't work. That's OK, it happens to everyone. -- Here are a few pointers on how to get things working. -- * If you get an error message, read what the message says. Sometimes that is all it takes. -- * Read the whole message: sometimes the most important part is at the beginning. -- * If the message doesn't make sense to you, try Google: often someone else has asked about the same issue and received a useful answer. -- * Simplify your code. * Look carefully at intermediate results. * Replace complicated data by something smaller and simpler. * In the process you may find your mistake. -- * Finding your bug usually involves double checking all the things you are sure you did right until you find the one you didn't. --- If you can't resolve things yourself you may need to ask for help. -- * When you ask for help, it is best to reduce your problem to a simple, reproducible example (`reprex`): The smallest set of expressions you can create that will show the problem starting with a fresh R session. -- * In the process of creating a `reprex` you may figure out what is wrong. -- * If you don't find your problem in putting together a `reprex`, you have something you can post on the **Q&A** discussion board that someone else can look at and try out. -- * To make it easier to someone to try out your reprex, it is important to post it as text that someone can copy and paste into their R session, **not** as a screen shot. -- Some References: * [Reprex do’s and don’ts](https://reprex.tidyverse.org/articles/reprex-dos-and-donts.html) vignette in the [`reprex`](https://cran.r-project.org/package=reprex) package. * [Common problems](https://r4ds.hadley.nz/data-visualize.html#common-problems) section in [R for Data Sceince](https://r4ds.hadley.nz/index.html). * [Debugging](https://adv-r.hadley.nz/debugging.html) chapter in [Advanced R](https://adv-r.hadley.nz/index.html).
//adapted from Emi Tanaka's gist at //https://gist.github.com/emitanaka/eaa258bb8471c041797ff377704c8505