README.md

ralphGetsTested

An R-Ladies Philly workshop on unit testing on Nov 11, 2021. An accompanying blog post and workshop recording are now available.

Abstract

In this workshop, Shannon Pileggi and Gordon Shotwell discuss how to get started with unit testing in R, which is formal automated testing of functions within packages. We demonstrate handy functions in usethis and devtools, strategies for writing tests, debugging techniques, and broad concepts in function writing that facilitate a smoother testing process.

This workshop picks up exactly where we left our little ralph (aka R-Ladies Philly) package one year ago with “Your first R package in 1 hour: Tools that make R package development easy”. Participants will get the most out of this workshop if they review those materials in advance, or if they are already familiar with building R packages with devtools and usethis.

Packages

Please install, or update, the following packages in advance of the workshop:

Get started

You can work either (1) locally or (2) with GitHub.

  1. To work locally, click the green Code button and download the zipped ralphGetsTested repository.

  2. To work through GitHub, fork and clone this repository with usethis::create_from_github("shannonpileggi/ralphGetsTested").

Keyboard shortcuts

Resources

Part 1: testing compute_corr()

Review the compute_corr() function and the available expectations in testthat.

Part 2: challenge function

Add the awesome_rladies function to the package.

awesome_rladies <- function(v) {

  sapply(v, function(x) {
    if (x == 1) {
      verb <- "is"
      noun <- "RLady"
    }

    if (x > 1) {
      verb <- "are"
      noun <- "RLadies"
    }

    as.character(glue::glue("There {verb} {x} awesome {noun}!"))
  })
}

and execute the function with:

awesome_rladies(1)
awesome_rladies(2)
awesome_rladies(1:2)


shannonpileggi/ralphGetsTested documentation built on Dec. 23, 2021, 1:20 a.m.