How to read R package documentation

2024-09-01

1 Introduction

When you want help with writing R code for data manipulation, statistical analyses or visualisation you might turn to various text books, blog posts, articles, internet searches or copy-and-paste from Stack Overflow or LLM output and cross your fingers. Package authors, however, have already written something just for you - the package user - to understand and use the functions in their package.

2 Function help

Run ?somefunction or help("somefunction") and you’ll be greeted with the help file for the function. In RStudio, this opens in the ‘Help’ pane. These help files give details about the function including how to use it, what the arguments mean and their default values, what the function will return and more. There are some standard sections you will find in these help files:

You might also find sections like:

A manual (in PDF or webpage form) containing a package’s help documentation can be found on its CRAN or R-universe (if the package is on R-universe) page.

3 Vignettes

Vignettes are longer documentation for a package. These can describe how to use and combine functions, recommend a workflow for using a package and provide further details.

Use browseVignettes("packagename") to browse the available vignettes for a package. Vignettes can also be found on a package’s CRAN or R-universe (under ‘articles’) page.

4 Package website

Packages often have a website (created using {pkgdown} or otherwise) showing the function help files, vignettes/articles and possibly further documentation. Some packages may have multiple websites (for example, the targets package has both a documentation website made with pkgdown and a manual).

Groups of packages that are designed to work together or built around the same theme (a ‘-verse’) might also have an overarching website (e.g. the website for the officeverse packages).

5 README and NEWS

These two documents can be found from a package’s CRAN/R-universe page or website. The README gives an overall introduction to the package, while NEWS describes changes to the package over time. The NEWS page can be useful if your code stops working or produces different output after you update a package to a newer version.

6 Published paper

The Journal of Statistical Software and other journals publish papers about software including R packages. Methodology papers may also have related packages. These papers can provide further background and details about a package. Links to relevant papers can hopefully be found from the package documentation such as in the citation information which can be found using citation("packagename").

7 Writing documentation

For more about R package documentation from the authoring side of things see the relevant chapters of ‘R Packages’.