Being introduced to a new R package is like going on a really good first date–you wish you had met the person sooner, you imagine doing all sorts of fun things together in the future, and you can’t wait to blog about the experience. Okay, maybe just the first two.
Such was my introduction to
assertr, a brilliant data validation package from rOpenSci. It was love at first sight. And much like a great date,
assertr’s bouquet of functions whisper sweet assurances into your console,
increasing your confidence, pushing you forward, and enhancing your desirability. Okay, maybe just the first two again.
Here’s a little demonstration.
Let’s create a data frame of hypothetical section codes, end dates, and students:
# A tibble: 5 × 3 section end_date students <chr> <date> <int> 1 APBIO142-262 2017-05-07 26 2 STATS110-684 2017-05-13 34 3 GEOM121-622 2017-05-15 27 4 APPSYCH121-158 2017-05-23 37 5 USHIS110-376 2017-05-26 38
Five hypothetical section codes, five hypothetical end dates, and five hypothetical quantities of students. Now, before I begin a formal analysis of this data, I may want to verify some assumptions. Namely, that the section codes are formatted correctly, that all sections terminate in May, and that each section has more than one and less than 40 students. Here I define a regular expression and set the range of end dates:
With these conditions set, I can test their validity via
verify, and confirm no section has more than 40 students via
# A tibble: 1 × 1 total_students <int> 1 162
Confidence! Failure of either condition would have thrown an error.
The assertr vignette does a terrific job explaining the nuances of
It’s worth a close read.
You can be sure that I will be going on many more dates with