<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/an-ode-to-testing-my-first-review/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://ropensci.org/blog/2018/03/13/ode-to-testing/"> rOpenSci - open tools for open science</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>To give you an idea of where I am in my <code>R</code> developer germination, I’d just started reading about <a rel="nofollow" href="http://r-pkgs.had.co.nz/tests.html" target="_blank">testing</a> when I received an email from <a rel="nofollow" href="https://ropensci.org/" target="_blank">@rOpenSci</a> inviting me to review the <a rel="nofollow" href="https://github.com/ropensci/weathercan" target="_blank"><code>weathercan</code></a> package. Many of us in the <code>R</code> community feel like <a rel="nofollow" href="https://en.wikipedia.org/wiki/Impostor_syndrome" target="_blank">imposters</a> when it comes to software development. In fact, as a statistician, it was a surprise to me when I was recently called a developer.</p>
<p>In terms of formal computer science training, I took one subject in first year, with the appropriate <a rel="nofollow" href="https://www.quickanddirtytips.com/education/grammar/abbreviations-acronyms-and-initialisms" target="_blank">initialism</a> <em>OOF</em>. Ostensibly, this was to school me in Object Oriented Fundamentals, but mostly educated me in just how much one person can pontificate about doubles and floats. I am almost always befuddled by regexes on the rare occasions I come across them.</p>
<p>However, through undertaking this review, which began with the revelation that I’m not alone in thinking, <a rel="nofollow" href="https://ropensci.org/blog/2017/08/22/first-package-review/" target="_blank">“What if I have absolutely nothing to say other than, yes, this is, in fact a package?!”</a>, I have come to see that all <code>R</code> users are <code>R</code> family (aw). No doubt these are well worn cobblestones that I judder my bicycle along. Despite this, it felt like a unique journey given my current fascination with testing.</p>
<p>Now I think any <code>R</code> user can be a <code>R</code>eviewer. That is, surely there’s something to be said for having someone who’s relatively uninitiated take your package for a whirl, at the very least. We all want our packages to be usable by all data science folk, not just advanced programmers.</p>
<p>I was delighted that the <a rel="nofollow" href="https://cran.r-project.org/web/packages/testthat/README.html" target="_blank"><code>testthat</code></a> package was part of the recommended reviewer workflow, as well as novel <a rel="nofollow" href="https://github.com/hadley/devtools" target="_blank"><code>devtools</code></a> functions. Reading the <a rel="nofollow" href="https://github.com/ropensci/onboarding/blob/master/packaging_guide.md" target="_blank">rOpenSci package guide</a> was a veritable font of good tips for someone who has only just begun building their first packages.</p>
<p>In this context, <em>testing</em> refers to a reproducible and more systematic approach to the kind of ad hoc console testing we <code>R</code> peeps do when writing functions. Does it output expected results? For a variety of inputs? Does it fail as it should when passed something it shouldn’t be?</p>
<p>It all seemed straightforward when I was reading about it, but sitting down to write tests for functions I hadn’t looked at in a while was a daunting proposition. In a review, however, you’re considering other people’s functions and the questions that spring to mind are so much more obvious in an objective setting. For starters, do the tests cover all functions?</p>
<p>I must admit to holding out actually looking at the test code, I wanted to get a feel for the syntax first and have a try myself. So, when I did pop the hood on the tests directory, I appreciated it more. Looking at the tests written for <code>weathercan</code>, it is clear <a rel="nofollow" href="https://github.com/steffilazerte" target="_blank">@steffilazerte</a> is a good ways past reading the testing chapter for the first time.</p>
<p>In a previous existence, I worked as a <a rel="nofollow" href="http://choosemaths.org.au/charles-gray/" target="_blank">musician</a> for almost two decades. Everything in my life has a soundtrack, and code is no exception. Looking through @steffilazerte’s tests, I heard this. My counterpoint lecturer said this is the single greatest piece of <a rel="nofollow" href="https://en.wikipedia.org/wiki/Polyphony" target="_blank">polyphony</a> (more than one melody at the same time).</p>
<p><center><br>
<iframe width="300" src="https://open.spotify.com/embed/track/0kPhDUZe8IdoFVC6e24CnC" height="380"></iframe><br>
</center></p>
<p>So, I dragged my feet a bit on the review, largely because the more I read the more I had to revisit testing on my own packages. Thinking about someone else’s tests made me want to explore what it was like to write a function along with its associated tests, <em>at the same time</em>.</p>
<p>I’m half-way through my doctorate in statistics, coming through from a maths background. So, up until now, my analyses have been horrible <a rel="nofollow" href="https://wiki.teamfortress.com/wiki/Towering_Pillar_of_Hats" target="_blank">towering pillars</a> of <code>R</code> script files which sourced functions from each other.</p>
<p><center><br>
<img alt="A Towering Pillar of Hats. https://wiki.teamfortress.com/w/images/f/f5/Towering_Pillar_of_Hats.png" src="https://i0.wp.com/ropensci.org/img/blog-images/2018-03-13-ode-to-testing/Towering_Pillar_of_Hats.png?w=456&ssl=1" data-recalc-dims="1"><br>

<div> <a rel="nofollow" href="https://wiki.teamfortress.com/wiki/Towering_Pillar_of_Hats" target="_blank">A Towering Pillar of Hats</a></div>
<p></p>
<p>Sometimes I’d source functions from other files but then worry they were broken. I heard this.</p>
<p><center><br>
<iframe allowfullscreen src="https://www.youtube.com/embed/sOUsbtUrXHk" width="450"></iframe><br>
</center></p>
<p>A wise man (<a rel="nofollow" href="https://github.com/njtierney" target="_blank">@njtierney</a>) recently said to me that statisticians can learn a lot from the development community, and he was not wrong.</p>
<p>In the past, if I came back to code after a couple of months I’d be plagued by anxiety when using a function. Is this the latest iteration? In which script file did I leave the latest iteration lying around? Does every other script file call the latest version?</p>
<p>Writing functions with documentation and tests <em>at the same time</em> feels like this.</p>
<p><center><br>
<iframe width="300" src="https://open.spotify.com/embed/track/1Wd7EwZcoAfCAEi9FF6G6b" height="380"></iframe><br>
</center></p>
<p>Now, not only do I know where everything is, but I can also trust that the functions work the way I intended in the documentation using testing. No longer will Current Charles be cursing Past Charles for her inscrutable code!</p>
<p><center><br>
<img alt="D.Va portrait. https://i0.wp.com/upload.wikimedia.org/wikipedia/en/5/55/D.Va_Overwatch.png?w=456&amp;ssl=1" src="https://i0.wp.com/upload.wikimedia.org/wikipedia/en/5/55/D.Va_Overwatch.png?w=456&ssl=1" data-recalc-dims="1"><br>

<div> <a rel="nofollow" href="https://en.wikipedia.org/wiki/D.Va" target="_blank">Writing GitHub-integrated packaged analyses makes me feel like this. And, <strong>yes</strong>, I really do main D.Va.</a></div>
<p></p>
	<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="https://ropensci.org/blog/2018/03/13/ode-to-testing/"> rOpenSci - open tools for open science</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a rel="nofollow" href="https://www.r-project.org/" title="The R Project for Statistical Computing">R</a> news and <a rel="nofollow" href="https://www.r-bloggers.com/search/tutorial" title="R tutorials">tutorials</a> on topics such as: <a rel="nofollow" href="https://www.r-bloggers.com/search/data%20science" title="Data science">Data science</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data" title="Big Data">Big Data, <a rel="nofollow" href="https://www.r-users.com/" title="R jobs">R jobs</a>, visualization (<a rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2" title="ggplot and ggplot2 tutorials">ggplot2</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/boxplot" title="Boxplots using lattice and ggplot2 tutorials">Boxplots</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/map" title="Maps and gis">maps</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/animation" title="Animation in R">animation</a>), programming (<a rel="nofollow" href="https://www.r-bloggers.com/search/RStudio" title="RStudio IDE for R">RStudio</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/sweave" title="Sweave and literate programming">Sweave</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX" title="LaTeX in R">LaTeX</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/SQL" title="SQL and databases">SQL</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/eclipse" title="Eclipse IDE for R">Eclipse</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/git" title="git and github, Version Control System">git</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/hadoop" title="Large data in R using Hadoop">hadoop</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping" title="Web Scraping of google, facebook, yahoo, twitter and more using R">Web Scraping</a>) statistics (<a rel="nofollow" href="https://www.r-bloggers.com/search/regression" title="Regressions and ANOVA analysis tutorials">regression</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/PCA" title="principal component analysis tutorial">PCA</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/time+series" title="Time series">time series</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/trading" title="finance trading">trading</a>) and more...
<img width="1" alt="" src="http://feeds.feedburner.com/~r/RBloggers/~4/uH7GAbFQ5qk" height="1"></a></div></center></center>