Building R Packages


Building R Packages

1. Introduction

Exegetic Analytics is a Data Science consultancy specialising in data acquisition and augmentation, data preparation, predictive analytics and machine learning. Our services are used by a range of industries from Education to Security, Food Delivery to Politics. Our consultants are based in Durban and Cape Town and we engage with clients all over the world. Our products and services are used by a multitude of industries including Aerospace, Education, Finance, Food and Transport.

Exegetic Analytics also offers training, with experienced and knowledgeable facilitators. Our courses focus on practical applications, working through examples and exercises based on real-world datasets.

All of our training packages include access to:

  • our online development environment and
  • detailed course material which participants will have continued access to even once the training has concluded.

For more information about what we do, you can refer to our website.

These are some of the companies who have benefitted from our trainning:

Take a look at our full list of courses to see what other training we have on offer.

Contact Us

If this proposal is of interest to you or you would like to hear more about what we do you can get in touch on or +27 73 805 7439.

2. Course Description

An R package is simply a group of related functions. Packages make it easier to organise and share code. It sounds complicated, but it’s not.

In this training you’ll learn how to use RStudio and a selection of packages, like {devtools} and {usethis}, to create your own packages.


Duration 1 day
Who should attend? Anybody who writes their own functions in R will benefit from knowing how to wrap those functions up in a package.
Objectives In this course you’ll learn how to turn a collection of functions into a package.
Outcomes 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.
Requirements Participants should be familiar with R and comfortable writing their own functions.

Return to our list of courses.

Course Outline

3. Course Outline

  • 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

Book now!

Training Philosophy

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. We will work through examples and exercises based on real datasets.


All you'll need is a computer with a browser and a decent internet connection. We'll be using an online development environment. This means that you can focus on learning and not on solving technical problems.

Of course, we are happy to help you get your local environment set up too! You can start by following these instructions.


The training package includes access to
  • our online development environment and
  • detailed course material (slides and scripts).

Return to our list of courses.