3. Libraries

flowchart LR
    A["`**Step 1**
    Scripts & Projects`"] --> B["`**Step 2**
    Working Directory`"] --> C["`**Step 3**
    Libraries`"] --> D["`**Step 4**
    Import & Export`"]
    style C fill:#1a1a1a,stroke:#1a1a1a,color:#fff
    linkStyle default stroke:#adb5bd,stroke-width:2px

Libraries

The power of R comes from user-created libraries. These are sometimes referred to as packages. To access these libraries in R you need to first install them with install.packages() and then load them with library().

Good news is that you only need to install packages once, but you need to load them to your script at the start of every session. Loading a library will then give you access to the functions within the library.

Let’s practice by loading the packages here and tidyverse:

### Install the packages (only needed once)
install.packages(c("here","tidyverse"))

### Load the packages (needed every session)
library(here)
library(tidyverse)

Getting help

All R packages on the CRAN network have accompanying documentation. Use ? to look up help on a specific function or package, and ?? to do a broad keyword search when you don’t know the exact name:

  • ?mean — opens the help page for the mean() function directly
  • ??regression — searches all installed help pages for the word “regression”
### Load packages first
library(here)
library(tidyverse)

### Get help on a specific function or package
?here
?tidyverse

### Search broadly if you don't know the exact name
??here