Chapter 8. Other Components

The first two chapters in this part of the book cover the two most obvious things that people distribute via an R package: functions (Chapter 6) and data (Chapter 7). But that’s not all it takes to make an R package. There are other package components that are either required, such as a DESCRIPTION file, or highly recommended, such as tests and documentation.

The next few parts of the book are organized around important concepts: dependencies, testing, and documentation. But before we dig into those topics, this chapter demystifies some package parts that are not needed in every package, but that are nice to be aware of.

Other Directories

Here are some top-level directories you might encounter in an R source package, in rough order of importance and frequency of use:

src/

This directory contains source and header files for compiled code, most often C and C++. This is an important technique that is used to make R packages more performant and to unlock the power of external libraries for R users. As of the second edition, the book no longer covers this topic, since a truly useful treatment of compiled code requires more space than we can give it here. The tidyverse generally uses the cpp11 package to connect C++ to R; most other packages use Rcpp, the most well-established package for integrating R and C++.

inst

This directory can hold arbitrary additional files that you want include in your package. This includes a few special files, like the ...

Get R Packages, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.