liveBook · Manning

Library() function

As explained in Statistics Slam Dunk

The library() function loads an installed R package into the current session.

The library() function loads an installed R package into the current session, making functions beyond base R available for data import, wrangling, visualization, and analysis. section 1.3 section 2.1

Use library() as part of a practical package workflow:

  • Install each package once with install.packages(), then load it whenever a script needs its functions. section 2.1
  • Place package-loading calls near the top of a script, before importing data or calling packaged functions. section 1.3 section 3.2
  • Load a package collection such as tidyverse to make its included packages available together. section 2.1
  • Call library() repeatedly for separate packages, or combine c() with lapply() when many packages are required. section 3.2

Load an analysis toolkit

Install tidyverse once, then load it at the start of a script. Load additional packages when the analysis needs SQL queries, assembled plots, specialized graphics, statistical tests, string handling, data cleaning, or image files. install.packages("tidyverse") library(tidyverse) library(sqldf) library(patchwork) For a larger package set: packages <- c("tidyverse", "networkD3", "patchwork") lapply(packages, library, character.only = TRUE) section 2.1 section 3.2 section 7.1

library(tidyverse)
library(reshape2)
library(sqldf)
library(patchwork)

Inspect the compact install.packages() command before loading tidyverse and using its functions. section 2.1

How Statistics Slam Dunk covers it

How deep it goes
Defines installation, loading order, repeated calls, grouped loading, and lapply(), but does not detail package internals.
Examples
Demonstrates tidyverse, sqldf, patchwork, networkD3, ggpubr, effsize, janitor, png, scales, and runner.
What it assumes
Assumes basic R use and teaches from zero that installation precedes loading and loading precedes packaged function calls.
What you can do after
Operate R packages by installing them once, loading them when needed, and calling their functions afterward.
How it connects
Connects R packages, base R, install.packages(), tidyverse, and lapply().

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Statistics Slam Dunk. The section links point to the parts of the book it draws on.