+ - 0:00:00
Notes for current slide
Notes for next slide

Finding Help


in the R wilderness

Julia Piaskowski

2022-03-03

1 / 15

What do you do when you need to solve a problem in R?

who ya gonna call

2 / 15

Check the documentation!

How do we do this?

?par
??plot

(Remember, you can spend 2 hours searching the web in order to save 15 minutes of reading the documentation).

3 / 15

No really, read the docs

2 main aspects of documentation:

  1. Function reference
  2. Vignettes

CRAN can be a good place to start.

tidyr example

4 / 15

exercise

5 / 15

Read your error messages

They are often telling you something important.

Informative error message I ignored

Informative error message I ignored

6 / 15

Still, error messages can be confusing

confused man meme at R error

7 / 15

Other help options

RStudio Community


rstudio community screenshot

8 / 15

Other help options

R4DS community


R for DS community screenshot

9 / 15

Other help options

Stack overflow


stack overflow screen shot

10 / 15

Read the source code

read the source, luke

(this will help improve your coding, too)

11 / 15

How to find source code

  • Type the function name in the console without parentheses:
lm

[suppressed output because it is long]

  • Sometimes this is not informative
c
## function (...) .Primitive("c")
subset
## function (x, ...)
## UseMethod("subset")
## <bytecode: 0x55f9840d3de0>
## <environment: namespace:base>
`[`
## .Primitive("[")
12 / 15

Use 'lookup' to find what you need

(Prior to 'lookup', finding source code was a real bugger

lookup checks CRAN, Bioconductor and GitHub!

lookup::lookup(`[`)
13 / 15

Miscellaneous R tip

How to find other methods associated with an R object

14 / 15

Miscellaneous R tip

How to find other methods associated with an R object

All R objects have a class assigned to them:

y <- rnorm(20); x <- y + rnorm(20)
m <- lm(y ~ x)
class(m)
## [1] "lm"
14 / 15

Once you know the object class, you can search on methods written for that class.

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
15 / 15

What do you do when you need to solve a problem in R?

who ya gonna call

2 / 15
Paused

Help

Keyboard shortcuts

, , Pg Up, k Go to previous slide
, , Pg Dn, Space, j Go to next slide
Home Go to first slide
End Go to last slide
Number + Return Go to specific slide
b / m / f Toggle blackout / mirrored / fullscreen mode
c Clone slideshow
p Toggle presenter mode
t Restart the presentation timer
?, h Toggle this help
Esc Back to slideshow