---
title: "Getting help with R"
author: "Ella Kaye"
date: "August 30th, 2017"
output:
  xaringan::moon_reader:
    css: wrug.css
    lib_dir: libs
    nature:
      highlightStyle: github
      highlightLines: true
      countIncrementalSlides: false
---

```{r setup, include=FALSE}
options(htmltools.dir.version = FALSE)
knitr::opts_chunk$set(collapse = TRUE)
```

class: center, middle

# Looking for answers

---

# Within R

```{r eval = FALSE}
# help with a specific function
?function_name

# for when you can't quite remember the function name
??something_like_function_name

# use auto-completion in RStudio to see what functions 
# are in a package
?package::

# find vignettes for installed (or specific) packages
browseVignettes()
browseVignettes("dplyr")
```

---

background-image: url(https://cdn.vox-cdn.com/uploads/chorus_asset/file/6466217/fixed-google-logo-font.png)
background-size: contain

---

background-image: url(http://i.imgur.com/Iafi6Pe.png)
background-size: contain

---

class: center, bottom
background-image: url(http://i.imgur.com/evseeMj.png)

---

background-image: url(https://upload.wikimedia.org/wikipedia/commons/f/f7/Stack_Overflow_logo.png)
background-size: contain


---

background-image: url(http://i.imgur.com/gSHGBKN.png)
background-size: contain

---
# Searching online

- In Google, include "r" and package name in your search

- Use [rseek.org](https://rseek.org) to search R documentation, discussion forums, blogs

- If trying to get help with an error, include the entire error message

- Use tags in [StackOverflow](https://stackoverflow.com)

    - rotate x axis labels [ggplot2] [r]

---

background-image: url(https://imgs.xkcd.com/comics/wisdom_of_the_ancients.png)
background-size: contain



---

# Digging deeper

- Issues on GitHub page

  - Check if it's a known problem awaiting a fix
  - see [this](https://github.com/hadley/r4ds/issues/585) and [this](https://github.com/tidyverse/googledrive/issues/99) for example
  
- Source code
  
  - Search for the package on GitHub
  - Download package source from CRAN (.tar.gz file)
  - `function_name`
  - Can you identify exactly what's causing the problem?

---



class: inverse, center, middle

## Always have a really good stab at finding an answer before asking a question

---

class: center, middle

# [xaringan example](https://github.com/yihui/xaringan/issues/56)

---

class: center, middle

# Asking questions

---

background-image: url(https://nypdecider.files.wordpress.com/2014/08/help-me-help-you.gif)
background-size: contain

---

## What makes a good question?

- **reproducible**

  - This means that you need to capture everything, i.e. include any library() calls at the top and create all necessary objects. 

- **minimal**

  - Strip away everything that is not directly related to your problem. This usually involves creating a much smaller and simpler R object than the one you’re facing in real life or even using built-in data.


---

## What makes a good question?

- **verifiable**

  - Actually reproduces the problem!

- Explain steps (using comments or rmarkdown)

- Include error messages, and possibly output of `sessionInfo()`

- Include what you've tried to fix it

---

class: center, middle
  
# Can be a lot of effort, but often the process of coming up with a good reproducible example (reprex) allows you to identify (and possibly solve) the problem

---

# The `reprex` package

```{r eval = FALSE}
install.packages("reprex")

# coming soon as part of the tidyverse
install.packages("tidyverse")
```

---

# Basic `reprex` steps

- write some R code
- copy it
- run `reprex()`
- paste

---

# `reprex()` demo

N.B. for the addin, need RStudio 1.1

---

# minimal dataset

- if possible, use a built-in, familiar dataset (e.g. `iris`, `mtcars`, [others](https://stat.ethz.ch/R-manual/R-devel/library/datasets/html/00Index.html))
- use `dput()`

```{r}
set.seed(1)
some_numbers <- sample(1:10)
dput(some_numbers)
```

Then copy and paste the above output into the reproducible example:

```{r}
my_data <- c(3L, 4L, 5L, 7L, 2L, 8L, 9L, 6L, 10L, 1L)
my_data
```
  

---

Also works with data frames. 

Need to send this to the console in order to be able to copy and paste!

```{r message = FALSE, warning = FALSE}
library(dplyr)

mtcars_small <- mtcars %>%
  select(1:7) %>%
  head()

dput(mtcars_small)

```

---

```{r}
mtcars2 <- structure(list(mpg = c(21, 21, 22.8, 21.4, 18.7, 18.1), cyl = c(6, 
6, 4, 6, 8, 6), disp = c(160, 160, 108, 258, 360, 225), hp = c(110, 
110, 93, 110, 175, 105), drat = c(3.9, 3.9, 3.85, 3.08, 3.15, 
2.76), wt = c(2.62, 2.875, 2.32, 3.215, 3.44, 3.46), qsec = c(16.46, 
17.02, 18.61, 19.44, 17.02, 20.22)), .Names = c("mpg", "cyl", 
"disp", "hp", "drat", "wt", "qsec"), row.names = c("Mazda RX4", 
"Mazda RX4 Wag", "Datsun 710", "Hornet 4 Drive", "Hornet Sportabout", 
"Valiant"), class = "data.frame")

mtcars2
```

---


# Where to ask

- mailing lists
  
  - There are 5 main [R mailing lists](https://www.r-project.org/mail.html) and 22 special interest group lists
  - [ggplot2](https://groups.google.com/forum/#!forum/ggplot2)
  - [manipulatr](https://groups.google.com/forum/#!forum/manipulatr) for tidyverse data manipulation queries

- StackOverflow (include tags)

- GitHub issues (if you're pretty sure you've uncovered a bug)

- Twitter with #rstats (#tidyverse also popular, if applicable)
    - with link to your reprex

---

class: center, middle

# [dplyrExtras example](https://github.com/skranz/dplyrExtras/issues/9)

---

class: center, middle

# [vignette example](https://github.com/rstudio/rmarkdown/issues/1119)


---

# Helping others

- Answer questions on StackOverflow [r] and twitter (#rstats)

- File issues


---

background-image: url(http://i.imgur.com/ZDSb6IE.png)
background-size: contain

---

background-image: url(http://i.imgur.com/FBCahms.png)
background-size: contain

---

# Resources 1

- StackOverflow guides and question on what makes a good question
  
  [https://stackoverflow.com/help/mcve](https://stackoverflow.com/help/mcve)
  
  [https://stackoverflow.com/help/how-to-ask](https://stackoverflow.com/help/how-to-ask)
  
  [https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example](https://stackoverflow.com/help/mcve)


---

# Resources 2

- reprex package on tidyverse site

  [http://reprex.tidyverse.org](http://reprex.tidyverse.org)

- reprex package on GitHub

  [https://github.com/tidyverse/reprex](https://github.com/tidyverse/reprex)

---

# Resources 3
- tidyverse guide to getting help

  [http://www.tidyverse.org/help](http://www.tidyverse.org/help/)
  
- tidyverse guide to contributing

  [http://www.tidyverse.org/contribute](http://www.tidyverse.org/contribute)
  
- Excellent blogpost (with gifs!)

  [http://www.njtierney.com/post/2017/01/11/magic-reprex](http://www.njtierney.com/post/2017/01/11/magic-reprex/)
  

---

# Resources 4
      
- Common errors in R

  [https://github.com/noamross/zero-dependency-problems/blob/master/misc/stack-overflow-common-r-errors.md](https://github.com/noamross/zero-dependency-problems/blob/master/misc/stack-overflow-common-r-errors.md)
  
  tl; dr: Most errors in R are due to looking for something that isn't there.
  
---

class: inverse, center, middle

# Thank you!
## Any questions?


## I'd love to hear from you!
[E.Kaye.1@warwick.ac.uk](mailto:E.Kaye.1@warwick.ac.uk)

[@ellamkaye](https://twitter.com/ellamkaye)

[ellakaye.rbind.io](https://ellakaye.rbind.io)

[github.com/EllaKaye](https://github.com/ellakaye)
