1 Preamble

Are you working on a R package accessing resources on the web, be it a cat facts API, a scientific data source or your system for Customer relationship management? As for all other packages, appropriate unit testing can make your code more robust. The unit testing of a package interacting with web resources, however, brings special challenges: dependence of tests on a good internet connection, testing in the absence of authentication secrets, etc. Having tests fail due to resources being down or slow, during development or on CRAN, means a time loss for everyone involved (slower development, messages from CRAN). Although some packages accessing remote resources are well tested, there is a lack of resources around best practices.

This book is meant to be a free, central reference for developers of R packages accessing web resources, to help them have a faster and more robust development. Our aim is to develop an useful guidance to go with the great recent tools that vcr, webmockr, httptest and webfakes are.

We expect you to know package development basics, and git.

Note related to previous versions: this book was intended as a detailed guide to using a particular suite of packages for HTTP mocking and testing in R code and/or packages, namely those maintained by Scott Chamberlain (crul, webmockr, vcr) but its scope has been extended to generalize the explanation of concepts to similar packages.

You can also read the PDF version or epub version of this book.

Thanks to contributors to the book: Alex Whan, Aurèle, Christophe Dervieux, Daniel Possenriede, Hugo Gruson, Lluís Revilla Sancho, Xavier A.

Project funded by rOpenSci (Scott Chamberlain’s work) & the R Consortium (Maëlle Salmon’s work).