Building R Packages

13 September 2019, Bandwidth Barn, Woodstock, Cape Town


In this course you’ll learn how to turn a collection of functions into a package.


After the course participants will be able to

  • set up the infrastructure for a package;
  • add functions and documentation;
  • create unit tests;
  • build the package; and
  • share the package via GitHub.

Who should attend?

Anybody who writes their own functions in R will benefit from knowing how to wrap those functions up in a package.

Course Content

  • Why Write R Packages?
    • Listing installed.packages()
    • Loading a package: library() versus require()
    • Installing
      • CRAN
      • GitHub
    • Package Management
      • {packrat}
      • {checkpoint}
  • A Simple Package
    • The anatomy of a package
      • Metadata: DESCRIPTION and NAMESPACE
      • Folders: R/, man/, data/ and tests/
    • Creating package infrastructure
    • Adding a function
    • Creating documentation
    • Adding data
    • Building
    • Installing
      • Where? Understanding .Library and .libPaths().
  • Documentation
  • Tests
    • The importance of tests
    • Writing simple tests with {testthat}
    • Running tests and interpreting results
    • Test driven development
  • Automation
    • Package setup with {usethis}
      • create_package()
      • use_r() and use_test()
      • use_git() and use_github()
    • Coding workflow with {devtools}
      • load_all()
      • document()
      • check()
      • build() and install()
  • Distribution
    • GitHub
    • Testing revisited: Continuous Integration with Travis
    • Preparing for CRAN


Participants should be familiar with R and comfortable writing their own functions.

Interactive course material

Our training emphasises practical skills. So, although you’ll be learning concepts and theory, you’ll see how everything is applied in the real world as we work through examples and exercises based on real datasets.

We like questions!

Having a firm understanding of the course content will result in you being able to confidently apply your new skills thereafter. So, if at any point you’re unsure of something, just ask!

Purchase a ticket

Contact us at if you have any questions.