Testing R Code

The basic premise of this book is that “Testing is the only way to be sure that your code, and your results, are correct”, and many programmers that I know would agree with this1. However, in practice, and for many different reasons, much research software is still developed with only a passing gesture to this principle. The author believes that “Testing code is conceptually easy; the hard part is developing habits to incorporate testing into your workflow”, and this may explain, at least in part, the shortfall of testing. Of course, software testing is a broad field that encompasses many issues from numerical stability and platform dependencies to graphical user interfaces, security and real-time processing. This means it is difficult to provide a small number of good, interoperable generic tools that cover all aspects of software development, whilst facilitating the development of these habits. However, it is possible when a specific programming language or environment is considered in isolation. In my opinion this book, in conjunction with the the tools that it employs, goes a long way towards realising this for the R programming environment. This book is suitable for anyone with a basic knowledge of the R programming language and is relevant for all who program using R, whether it be for creating small scripts, complete packages or anything in between. The book sets out by distinguishing between two types of testing – development time and run time. In the author’s words – “The point of development time testing is to make sure that you [the programmer] have not done something stupid. By contrast, the point of runtime testing is to make sure that the user has not done something stupid.” These two types are examined separately in Chapters 2 and 3, which detail the two key packages on which the book is based assertive (Cotton 2016) for run time testing (maintained by the author) and testthat (Wickham 2011) for development time testing. They also include numerous examples and exercises, with solutions, which underpin the authors imperative “Attempt all exercises!”. Having attempted most of them myself it is clear that they are well thought out and instructive. Both chapters are very complete, and at the end of reading them I was pleasantly surprised as to how quickly I could implement the methods they introduced into