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



R packages

Dr. Mine Dogucu

1 / 25

Default

Microsoft products have Copyright. Images used based on fair use for educational purposes.

Optional

2 / 25

R packages

When you download R, you actually download base R.

3 / 25

R packages

When you download R, you actually download base R.

But there are MANY optional packages you can download.

4 / 25

R packages

There are more than 15000 R packages.

5 / 25

R packages

There are more than 15000 R packages.

Good part: There is an R package for (almost) everything, from complex statistical modeling packages to baby names.

6 / 25

R packages

There are more than 15000 R packages.

Good part: There is an R package for (almost) everything, from complex statistical modeling packages to baby names.

Bad part: At the beginning it can feel overwhelming.

7 / 25

R packages

All this time we have actually been using R packages.

8 / 25

R packages

What do R packages have? All sorts of things but mainly

  • functions

  • datasets

9 / 25

R packages

Try running the following code:

beep()
## Error in beep(): could not find function "beep"

Why are we seeing this error?

10 / 25

Installing packages

11 / 25

Using install.packages()

In your Console, install the beepr package

install.packages("beepr")

We do this in the Console because we only need to do it once.

12 / 25

Using Packages pane

Packages Pane > Install

13 / 25

Letting RStudio Install

If you save your file and using a package RStudio will tell you that you have not installed the package.

14 / 25

Using packages

15 / 25

Using beep() from beepr

Option 1

library(beepr)
beep()

More common usage. Useful if you are going to use multiple functions from the same package. E.g. we have used many functions (ggplot, aes, geom_...) from the ggplot2 package. In such cases, usual practice is to put the library name in the first R chunk in the .Rmd file.

Option 2

beepr::beep()

Useful when you are going to use a function once or few times. Also useful if there are any conflicts. For instance if there is some other package in your environment that has a beep() function that prints the word beep, you would want to distinguish the beep function from the beepr package and the beep function from the other imaginary package.

16 / 25

17 / 25

Open Source

Any one around the world can create R packages.

18 / 25

Open Source

Any one around the world can create R packages.

Good part: We are able to do pretty much anything R because someone from around the world has developed the package and shared it.

19 / 25

Open Source

Any one around the world can create R packages.

Good part: We are able to do pretty much anything R because someone from around the world has developed the package and shared it.

Bad part: The language can be inconsistent.

20 / 25

Open Source

Any one around the world can create R packages.

Good part: We are able to do pretty much anything R because someone from around the world has developed the package and shared it.

Bad part: The language can be inconsistent.

Good news: We have tidyverse.

21 / 25

Tidyverse

The tidyverse is an opinionated collection of R packages designed for data science. All packages share an underlying design philosophy, grammar, and data structures. tidyverse.org

22 / 25

Tidyverse

In short, tidyverse is a family of packages. From practical stand point, you can install many tidyverse packages at once (and you did this). By doing that you installed all the following packages.

  • ggplot2
  • dplyr
  • tidyr
  • readr
  • purrr
  • tibble
  • stringr
  • forcats
23 / 25

We can also load the tidyverse packages all at the same time.

library(tidyverse)
24 / 25

Fun fact

library(magrittr)

Treachery of Images by René Magritte

Image for Treachery of Images is from University of Alabama website and used under fair use for educational purposes.

25 / 25

Default

Microsoft products have Copyright. Images used based on fair use for educational purposes.

Optional

2 / 25
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