liveBook · Manning

Package

As explained in Statistics Slam Dunk

A software package is a distributable collection of code, data, documentation, and supporting resources that extends a programming environment.

A software package is a distributable collection of source code, data, documentation, and supporting resources that extends a programming environment. In R, packages let programmers add capabilities beyond base R without changing its original code base. section 1.2.2 section 2.1

Use packages through a simple installation-and-loading workflow:

  • Install a package once with base R’s install.packages() function, commonly using a package available from CRAN or occasionally GitHub. section 2.1
  • Load the package whenever and wherever its functions will be used by calling library() before the rest of the script. section 2.1 section 3.2
  • Use packages such as tidyverse, dplyr, tidyr, ggplot2, sqldf, patchwork, and networkD3 for wrangling, querying, visualization, and flow diagrams. section 2.1 section 3.2
  • Load many packages sequentially with library(), or store their names in a vector and pass that vector to lapply(). section 3.2

Loading analysis tools

Install the tidyverse once, then load it before data preparation or visualization: install.packages("tidyverse"); library(tidyverse). A larger script can instead use packages <- c("tidyverse", "networkD3", "patchwork") followed by lapply(packages, library, character.only = TRUE). section 2.1 section 3.2

Figure 1.3 Package counts in CRAN displayed by publication year
CH01_F03_Sutton

Browse the CRAN package-count figure to see the expanding ecosystem of available R packages. section 1.2.2

How Statistics Slam Dunk covers it

How deep it goes
Explains package contents, installation, loading order, and multi-package loading, but stops short of package development.
Examples
Uses install.packages(), library(), tidyverse, networkD3, patchwork, and lapply() package-loading examples.
What it assumes
Assumes installed R and RStudio, while teaching package installation, loading, and use beyond base R.
What you can do after
Apply packages by installing them once, loading them before use, and calling their functions in R analysis scripts.
How it connects
Connects packages with base R, RStudio, CRAN, GitHub, tidyverse, data wrangling, and data visualization.

Also explained in

Compare how 8 books explain package →

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.