class: center, middle, inverse, title-slide # Finding Help ## ⚔
in the R wilderness ### Julia Piaskowski ### 2022-03-03 --- class: center, middle ## What do you do when you need to solve a problem in R? ![who ya gonna call](images/ghostbusters.jpeg) --- # Check the documentation! How do we do this? ```r ?par ??plot ``` (*Remember, you can spend 2 hours searching the web in order to save 15 minutes of reading the documentation).* --- # No really, read the docs 2 main aspects of documentation: 1. Function reference 1. Vignettes [CRAN](https://cran.r-project.org/web/packages/available_packages_by_name.html) can be a good place to start. [tidyr example](https://CRAN.R-project.org/package=tidyr) --- class: center, middle, inverse ## [exercise](exercises/exercise-3.html) --- # Read your error messages *They are often telling you something important.* <div class="figure"> <img src="images/tweet_ignored_error.png" alt="Informative error message I ignored" width="80%" /> <p class="caption">Informative error message I ignored</p> </div> --- # Still, error messages can be confusing ![confused man meme at R error](images/r_function_error.jpg) --- ## Other help options [RStudio Community](https://community.rstudio.com/) <br> ![rstudio community screenshot](images/rstudio_community.png) --- ## Other help options [R4DS community](https://www.rfordatasci.com/) <br> ![R for DS community screenshot](images/r4ds_screenshot.png) --- ## Other help options [Stack overflow](https://stackoverflow.com/) <br> ![stack overflow screen shot](images/stackoverflow_screenshot.png) --- # Read the source code ![read the source, luke](images/luke_source_code.jpeg) *(this will help improve your coding, too)* --- # How to find source code * Type the function name in the console without parentheses: ```r lm ``` *[suppressed output because it is long]* <br><br> * Sometimes this is not informative ```r c ``` ``` ## function (...) .Primitive("c") ``` ```r subset ``` ``` ## function (x, ...) ## UseMethod("subset") ## <bytecode: 0x55f9840d3de0> ## <environment: namespace:base> ``` ```r `[` ``` ``` ## .Primitive("[") ``` --- # Use 'lookup' to find what you need *(Prior to 'lookup', finding source code was a real [bugger](https://github.com/jennybc/access-r-source#readme)* **lookup** checks CRAN, Bioconductor and GitHub! ```r lookup::lookup(`[`) ``` --- # Miscellaneous R tip #### How to find other methods associated with an R object -- All R objects have a class assigned to them: ```r y <- rnorm(20); x <- y + rnorm(20) m <- lm(y ~ x) class(m) ``` ``` ## [1] "lm" ``` --- Once you know the object class, you can search on methods written for that class. ```r methods(class = "lm") ``` ``` ## [1] add1 alias anova case.names coerce ## [6] confint cooks.distance deviance dfbeta dfbetas ## [11] drop1 dummy.coef effects extractAIC family ## [16] formula hatvalues influence initialize kappa ## [21] labels logLik model.frame model.matrix nobs ## [26] plot predict print proj qr ## [31] residuals rstandard rstudent show simulate ## [36] slotsFromS3 summary variable.names vcov ## see '?methods' for accessing help and source code ```