Coding Club: Creating an R Package

Author

Lisa DeBruine

Overview

Making an R package develops generic coding skills and gives you valuable insight to how R works. We’ll cover setting up a package project, creating functions, documenting them with roxygen, creating vignettes, unit testing, package testing, version control with git, and distribution with github.

You will need only very basic R skills and a willingness to learn. The only people this would not be suitable for are those with zero previous experience in R (unless you know you pick up coding languages quickly). If you can install packages and have written an analysis script, you’ll be fine.

Demo Package

This book contains all of the instructions to create your first R package. But if you fall behind and need to download the most recent version of the demopkg, visit https://github.com/psyteachr/demopkg and check the README for download instructions.

Schedule

This originally ran as a weekly online workshop in 2022 for the PsyTeachR Coding Club at the University of Glasgow School of Psychology & Neuroscience. The videos are on a playlist on YouTube.

  1. Setting up a package project (2022-10-05) Recording

    Create a package project and edit the default files. Well start using the most helpful package, usethis.

  2. Adding Data (2022-10-12) Recording

    Add datasets to your package and document them with a codebook. You can use our demo data or your own.

  3. Custom Functions (2022-10-19) Recording

    Learn to write custom functions and include them in your package.

  4. Documentation (2022-10-26) Recording

    Write function documentation using the roxygen format. This is what creates the help documentation for functions.

  5. Unit Tests (2022-11-02) Recording

    Write unit tests for your custom functions using testthat.

  6. Vignettes (2022-11-09) Recording

    Include your study analysis code as a package vignette.

  7. Pkgdown Websites (2022-11-16) Recording

    Create a package website using pkgdown.

  8. Package Maintenance (2022-11-23) Recording

    How to run CMD-check to make sure everything is put together right, and how to troubleshoot the inevitable problems.

  9. Sharing your package (2022-12-07) Recording

    Set up a github account and make a package repository to share your package and pkgdown website.

Resources