checkr: An R package for Assertive Programming

knitr::opts_chunk$set(echo = TRUE, warning = FALSE, messages = FALSE, fig.width = 8, fig.height = 12)

Summary

Assertive programming follows the principles of fail fast and fail visibly [@shore_fail_2004]. It is implemented by issuing an informative error message if function arguments fail to satisfy specific criteria. This is particularly important in R because it is dynamically-typed language [@hutchison_evaluating_2012].

checkr is a dependency-free, pipe-friendly R package of assertive functions to check the properties of common R objects. In the case of failure, the functions, which are designed to be used in scripts and packages, issue informative error messages.

The most interesting and unique feature of checkr is the use of objects to check the values of other objects using an elegant and expressive syntax. For example the values in the height, mass and hair_color columns in the starwars data frame are checked using the syntax.

library(checkr)

check_data(dplyr::starwars, values = list(
  height = c(66L, 264L),
  mass = c(20,1358, NA),
  hair_color = c("blond", "brown", "black", NA)), error = FALSE)

The software archive is at https://github.com/poissonconsulting/checkr.

References



Try the checkr package in your browser

Any scripts or data that you put into this service are public.

checkr documentation built on May 1, 2019, 6:59 p.m.