class: center, middle, inverse, title-slide # Troubleshooting & Debugging ### Bora Jin --- layout: true <div class="my-footer"> <span> <a href="https://introds.org" target="_blank">introds.org</a> </span> </div> --- ## Material 📖 Read [How to read an R help page (Section A.1.1)](https://socviz.co/appendix.html#a-little-more-about-r) --- ## Today's Goal - Learn troubleshooting strategies - Practice debugging some common errors "Each time you figure out the solution to your problem, you acquire more and more knowledge about how and why things go wrong, and more confidence about how to tackle the next glitch that comes along." - from today's material --- ## Quiz **Functions take inputs, perform actions, and return outputs.** **Q - In an R help page, which sections do we read for information on how to use the function?** -- Usage -- - function's name - named arguments in () **in the order the function expects the arguments** - some arguments come with default values - but you must specify values for arguments without default values --- ## Quiz **Q - In an R help page, which sections do we read for information on inputs?** -- Arguments -- - detailed information on each argument - it tells you the class of inputs that the function expects -- **Q - In an R help page, which sections do we read for information on actions?** -- Description or title -- - describes what the function does --- ## Quiz **Q - In an R help page, which sections do we read for information on outputs?** -- Value -- - function's output **in the order the function returns values** - can be a single number, a list with multiple objects, a data frame, a plot, or a model --- ## Quiz **Q - In an R help page, which sections do we read for information on examples?** -- Examples -- - simple and quick-to-run examples to help you understand how to use the function and what to use it on -- **Q - What if we want to learn more about the package as a whole, rather than a few specific functions?** -- Demos and Vignettes -- - you may google directly the package name - or click the link at the end of the help page to visit the package's index page --- ## Example ```r ?qnorm ``` -- ```r ?lm ``` --- ## Example ```r qnorm(0.5) # default values ``` ``` ## [1] 0 ``` -- ```r qnorm(0.5, 2, 1) # in default order ``` ``` ## [1] 2 ``` -- ```r qnorm(0.5, 1, 2) # mean and sd values swapped ``` ``` ## [1] 1 ``` -- ```r qnorm(0.5, sd = 1, mean = 2) # mean and sd order swapped but same as qnorm(0.5, 2, 1) ``` ``` ## [1] 2 ``` --- class: middle, center # Questions? --- ## Let's Practice Together! Go to [AE 09: `R` Errors, Troubleshooting, and Getting Help](https://sta199-summer22.netlify.app/appex/ae09_BJ.html) --- ## Bulletin - Watch videos for [Prepare: May 25](https://sta199-summer22.netlify.app/prepare/week03_may25_BJ.html) - HW 01 due tonight at 11:59pm - Submit your `ae08` and `ae09`