docxtools is an R package for helping me create classroom and workshop handouts as well as to practice creating and maintaining an R package. In the update just completed, I developed unit tests and fixed some bugs. The latest version can be downloaded from CRAN; the development version from GitHub using devtools::install_github(“graphdr/docxtools”).
The main change to format_engr() was to add a new optional logical argument, ambig_0_adj, that allows a user to decide if the ambiguity in significant digits and trailing zeros is to be adjusted by using engineering notation. For example, the number 120 has an ambiguous zero; we don’t know if this value has 2 or 3 significant digits. However, the ambiguity can be eliminated by writing the number in engineering format. With two significant digits, the number is expressed 0.12 × 10³; with three, 0.120 × 10³, etc.
Minor improvements to format_engr() include
- Requiring the input to be a data frame.
- Revising the vignettes and examples.
- Corrected an error caused by an incorrect use of str_trunc(); replaced it with str_sub(). Both functions from the stringr package.
- Variables of the types “date”, “factor”, “ordered factor”, and “character” are now (correctly) ignored by the formatting routine.
Unit-testing turned out to be fun! I used the covr package to check coverage. The output of package_coverage(type = “tests”) is a table in the RStudio Viewer pane that color codes the percent coverage and highlights in green the code lines tested and in red the lines not tested. The game was to write tests to turn red to green; bonus points for doing it in the fewest possible tests. Of course, 100% coverage doesn’t mean the code is correct! But it was fun anyway. It definitely got me thinking about what a chunk of code is supposed to do, what the input and output are expected to be, and how it might go wrong. The testing chapter in R Packages by Hadley Wickham was very helpful.
Many thanks to the volunteers at CRAN. Just a few days after I updated the package to CRAN, I received an automated message letting me know that the upcoming release of ggplot2 caused docxtools to break. The problem turned out to be in my unit tests, not a bug in ggplot2. I fixed the problem and requested another CRAN update. They graciously accepted my new release even though my previous release was just 5 days earlier.
Leave a Reply
You must be logged in to post a comment.