<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/community-call-summary-code-review-in-the-lab/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://ropensci.org/blog/2018/11/29/codereview/"> 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>Although there are increasing incentives and pressures for researchers to share code (even for projects that are not essentially computational), practices vary widely and standards are mostly non-existent. The practice of <em>reviewing</em> code then falls to researchers and research groups before publication. With that in mind, rOpenSci hosted a <a rel="nofollow" href="https://discuss.ropensci.org/t/how-do-you-review-code-that-accompanies-a-research-project-or-paper-help-ropensci-plan-a-community-call" target="_blank">discussion thread</a> and a <a rel="nofollow" href="https://ropensci.org/commcalls/2018-10-16/" target="_blank">community call</a> to bring together different researchers for a conversation about current practices, and challenges in reviewing code in the lab.</p>
<p>On the call, we heard from Carl Boettiger (UC Berkeley/rOpenSci), Melanie Frazier &amp; Julia Stewart Lowndes (National Center for Ecological Analysis and Synthesis), and Hao Ye (U. Florida/Weecology). Between the presentations discussion, and <a rel="nofollow" href="https://docs.google.com/document/d/1LfyhgsbVgLWgWPhS0nbaBIZSFjireEBBSYL4PmhUJis/edit?usp=sharing" target="_blank">active</a> <a rel="nofollow" href="https://discuss.ropensci.org/t/how-do-you-review-code-that-accompanies-a-research-project-or-paper-help-ropensci-plan-a-community-call/1321/29" target="_blank">commenting</a> by many in the community, we learned how different groups approached the problem.</p>
<p>What did we learn? A great deal! The community uses code in many different ways in research, and practices often differed accordingly.</p>
<h3>Project Structure: A Minimum Prerequisite</h3>
<p>The conversation around code review frequently diverted to discussion of <em>project structures</em> and <em>coding practices</em>. This was related to a common theme we heard from participants: <strong>agreement around workflows and project organization is a minimum prerequisite for a review process</strong>.</p>
<p>While different research groups had different standards for what these practices are, according to different use-cases, all had <strong>minimum project standards to make code <em>reviewable</em></strong>. These ranged from simply having an adequate README explaining the project structure and how to run it, to using R-markdown documents, to <a rel="nofollow" href="https://github.com/ropensci/rrrpkg" target="_blank">research compendia</a> and <a rel="nofollow" href="https://github.com/noamross/nyhackr-docker-talk#links-to-topics-and-resources-dicussed-in-the-talk-and-more" target="_blank">containerized</a> projects with <a rel="nofollow" href="http://r-pkgs.had.co.nz/tests.html" target="_blank">automated testing</a> and <a rel="nofollow" href="https://juliasilge.com/blog/beginners-guide-to-travis/" target="_blank">continuous integration</a>.</p>
<p>A few themes held across project types. First, <strong>documentation was the highest priority</strong> – inadequately documented projects were much more difficult to review. Secondly, as <strong>projects go more complex, it was helpful to break them up or modularize them</strong>, spinning off re-usable code into standalone, reusable packages and separating data from analysis code. Thirdly, as projects became either more complex or became reusable tools rather than one-off analyses, the degree of stringency needed for documentation, automated testing, and automated tools like <a rel="nofollow" href="https://github.com/jimhester/lintr" target="_blank">linters</a> increases. These latter two points are necessary as large, complex projects are challenging to review as a whole. Complex projects were also more reviewable when they produced and communicated outputs from the intermediate steps in pipelines, rather than run as a single black-box.</p>
<p>There was also considerable interest and hope in projects like <a rel="nofollow" href="https://mybinder.org/" target="_blank">Binder</a> and <a rel="nofollow" href="https://codeocean.com/" target="_blank">Code Ocean</a> (which we learned more about from <a rel="nofollow" href="https://discuss.ropensci.org/t/how-do-you-review-code-that-accompanies-a-research-project-or-paper-help-ropensci-plan-a-community-call/1321/46" target="_blank">April Clyburne-Sherin</a>), which provide a shared environment for reviewers to review code and, simultaneously, minimum project structure to which projects must adhere. As these emerge as standards for code review structures <em>across</em> labs, they influence practices within labs.</p>
<h3>Teams and Training: Necessary Conditions</h3>
<p>Another area all our presenters emphasized was the need to create a <em>social environment</em> conducive to code review, especially given the mixed backgrounds of most research teams. This involves agreeing on and <strong>communicating standards</strong>, <strong>building a knowledge base</strong>, and practicing a <strong>culture of feedback</strong>.</p>
<p>Standards, like the ones describing project structures, need to be set for the team and communicated. At NCEAS, the Ocean Health Index team has a <a rel="nofollow" href="https://github.com/OHI-Science/ohiprep/blob/master/src/dataOrganization_SOP.md" target="_blank">standard operating procedure</a> document that describes file organization and naming conventions for the large shared code repositories. This document is maintained along with the repository and referenced in READMEs. Having written standards and <a rel="nofollow" href="https://www.nature.com/articles/s41559-017-0160" target="_blank">workflows</a> are important for collaborating within the team, and also for onboarding new team members.</p>
<p>Most teams also had a mix of practices for building up a team knowledge base. This involved written resources like a team wiki, commonly shared practices from external resources like <a rel="nofollow" href="https://carpentries.org/" target="_blank">Software Carpentry</a>, and regular team time for things like formal group learning on topics like abstraction and <a rel="nofollow" href="https://en.wikipedia.org/wiki/Code_refactoring" target="_blank">refactoring</a>. Having the code from different projects open and shareable across the team is also important, so that there is a sufficient source of examples of previous practice.</p>
<p>Finally, participants emphasized the need for creating a culture where people know mistakes happen and they should expect them. When finding, reviewing, and fixing mistakes is <em>part of the workflow</em>, people are more comfortable discussing and learning from them.</p>
<h3>Review Itself: Few Common Practices</h3>
<p>While the concept of standards and standardized workflows was common to most lab groups, and increasingly formalized, the review process was not. Code review itself is frequently described as “more of a process than an event”, “rarely explicit”, “very ad hoc”, and takes place in a variety of formats: one-on-one meetings, comments on committed code, pair programming sessions. In some cases, there were more formal processes for specific projects, such as updates to the shared codebase of a major project.</p>
<p>Many presenters and commenters described the importance of using a <strong>checklist for review</strong>. Many in the <a rel="nofollow" href="https://discuss.ropensci.org/t/how-do-you-review-code-that-accompanies-a-research-project-or-paper-help-ropensci-plan-a-community-call/1321" target="_blank">discussion thread</a> offered their own checklists, both formal and informal. These checklists vary a great deal – in many cases they cover general areas such as “Can one run the code?”, and “Is there documentation?” In cases where projects in a group run deal with similar challenges, they can be more specific, like, “Are NAs handled appropriately in joins?” or “Does the pipeline run on new and old versions of the data pulled from version control?”</p>
<p>Some areas cropped up as common challenges. For instance – to what extent should feedback on research code emphasize refactoring, or optimization? While it was generally agreed that refactoring is more important for more general, highly reused code, it is by no means clear how much so. For rapidly developing research code, how much should testing be emphasized? Another area where the right approach to reviewing was unclear was in long-running, computationally-intense workflows. For such projects, can a reviewer or an automatic test suite be expected to reproduce the results?</p>
<p>Finally, one useful note was that review in in-person meetings can make it more challenging to maintain a written record of changes compared to interactions via systems like GitHub. The team from NCEAS noted that they use GitHub issues as a note-taking system so that discussions would be recorded in the same place as on-line discussion, and Weecology used co-authored commits to record changes from pair-programming sessions.</p>
<p>How does your group review code that accompanies a research project or manuscript? Have you tried to implement any of these approaches after hearing about them here? Share your experience in the comments below.</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/11/29/codereview/"> 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/AJvC1g-QrJ4" height="1"></a></div>