R Package Essentials

I first learnt to write an R package from Hilary Parker’s famous blog post, “Writing an R package from scratch”. Then I consulted Hadley Wickham’s “R packages” book (1st edition). I consider the “R packages” book (now in its second edition, by Hadley Wickham and Jenny Bryan), to be the authority on best practices for package development, alongside the rOpenSci guide, “rOpenSci Packages: Development, Maintenance, and Peer Review”, by Salmon et al. These are excellent pieces of reference test, however I think there is a need for a resource that sits somewhere between a blog post on making an R package, and resource. I want something that contains just enough information to get you started on the right path to making an R package. This is what that book represents to me. Along the way I’ll include breadcrumbs to other resources to look into when you want to learn more.

Author

Nicholas Tierney

Published

April 8, 2025

About this

This is a book on the essential components of creating an R package. It is aimed at those who want to learn how to make R packages. You probably have written some functions, but if you haven’t, we discuss how to do that. I care a lot about writing functions, and have a lot of thoughts and ideas on how to do it.

It was initially developed as a full-day hour workshop, “R package essentials”. It is a developed into a resource that will grow and change over time as a living book.

This book aims to teach the following:

  • Installation and setup of dependencies
    • git + github
    • R, RStudio
    • package dependencies
  • Function essentials
    • DRY;DRY (Don’t Repeat Yourself; Don’t Reread Yourself)
    • Expression
    • Finding the inputs
  • Moving a script to a series of functions
  • Create package barebones with create_package()
  • How to add dependencies with use_package() - DESCRIPTION file
  • How to add documentation with roxygen2
  • Why you should use R CMD Check
  • How to add data to a package
  • How to add a README
  • How to put your package on github
  • How to add vignettes
  • Writing tests
  • Using a NEWS file
  • Adding a website
  • Using Continuous Integration to check and test
  • Publishing your software on R universe

Getting course materials

Course materials are in the github repository njtierney/learned. These can be downloaded by using the following command from the usethis package:

usethis::use_course("njtierney/learned")

Licence

Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License.