Introduction to R Packages

Do you have R code you want to share? You can transform your R code into a shareable tool by developing it into an R package. This course bridges the gap between writing isolated R functions and creating documented packages that can be easily distributed, and is designed for those who might be curious about R package development but haven’t had the time or guidance to get started.

You’ll learn the essential tools of the trade: usethis and devtools for package structure, roxygen2 for documentation, testthat for testing, and Git/GitHub for sharing your work.

Whether you’re looking to organise your personal code collection or contribute to the broader R ecosystem, this course provides the foundation you need.

Prerequisites:

  • Comfortable with some R fundamentals (data types, functions, reading data).
  • Experience writing basic R scripts.
  • No prior experience with package development required.

Learning Outcomes:

  • Create the basic structure of an R package.
  • Manage dependencies with usethis and devtools.
  • Create documentation with roxygen2.
  • Write and run unit tests with testthat to verify package functionality.
  • Use Git and GitHub to put your R package online.
  • Understand next steps for advanced package development, including:
    • Automatically run tests with continuous integration via GitHub Actions.
    • Make your R package easily installable with the R Universe.
    • Create professional package websites using pkgdown.
Author

Nicholas Tierney

Published

September 8, 2025

About this

This book is an introduction to creating an R package. It focusses on building an R package with 1-2 functions, the praiseme package (modelled on the praise package).

This book is a resource that will grow and change over time as a living book.

After reading this book and doing the workshop, you should feel comfortable doing the following:

  • Create the basic structure of an R package.
  • Manage dependencies with usethis and devtools.
  • Create documentation with roxygen2.
  • Write and run unit tests with testthat to verify package functionality.
  • Use Git and GitHub to put your R package online.
  • Understand next steps for advanced package development, including:
    • Automatically run tests with continuous integration via GitHub Actions.
    • Create professional package websites using pkgdown.
    • Make your R package easily installable with the R Universe.

Licence

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