<p><div><div><div><div data-width="100" data-show-faces="false" data-send="true" data-layout="button_count" data-height="21" data-href="https://www.r-bloggers.com/why-you-need-version-control/"></div></div><div><a data-url="https://www.r-bloggers.com/why-you-need-version-control/" data-counturl="https://www.r-bloggers.com/why-you-need-version-control/" data-count="horizontal" data-text="Why you need version control" class="twitter-share-button" data-via="rbloggers" href="https://twitter.com/share"></a></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://ellisp.github.io/blog/2016/09/16/version-control"> Peter's stats stuff - R</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>I recently had an email exchange with a seasoned, well respected analytical professional which included the following (from them, not me): “… my versioning is to have multiple versions of files and to use naming conventions… it works really well.”</p>
<p>This is a very smart, competent researcher who has delivered great results, doing innovative and influential work albeit generally in very small teams of one or two people doing coding. I’m sure the naming conventions <em>do</em> work for them, and by any reasonable definition they are highly successful with that approach. But it wouldn’t work in my world with my sort and scale of tasks. I wouldn’t run my blog that way, never mind a critical project in my day job. In this blog post I want to explain why I think that analysts using naming conventions should move to version control software like <a target="_blank" href="https://git-scm.com/">Git</a> or <a target="_blank" href="https://subversion.apache.org/">Subversion</a>.</p>
<h2>A classification of analysts</h2>
<p>In my observation, it’s possible to divide analysts (and analytics teams) into four categories:</p>
<ol>
<li>
<p>Those for whom most work is done in Excel, particularly data management and presentation and visualisation of results. Specialist tools like SAS, Stata, Matlab, R or E-views used only for statistical/econometric modelling tasks that are beyond Excel.</p>
</li>
<li>
<p>Those for whom most work, including data management and visualisation, is done in a coding language which is usually one of R, SAS or Python plus SQL, but version control is limited to copies of files and date-stamped naming conventions.</p>
</li>
<li>
<p>Like #2, but with version control software, a coding style guide, and thorough peer review processes.</p>
</li>
<li>
<p>Like #3, but with more good practice borrowed from the software development world – like unit testing, regression testing, validation checks, release cycles, modular code, high coverage documentation, and continuous integration.</p>
</li>
</ol>
<p>Obviously this is a value-laden list for me, and while people in all four categories do important and useful work I think those analysts in categories 3 and 4 are much more valuable than those in 1 and 2. In particular, managing a team of analysts who aim to be continuously in the best practice category, I can have confidence in efficiency, quality control, ability to scale up to very large and complex data-intensive problems, and institutional memory and sustainability.</p>
<p>All the progressions between these categories are important (and involve a cultural shift with big changes in work practices needed), but I think a threshhold of professionalism is really crossed in the progression from category #2 to #3 – the adoption of version control and the introduction of some basic disciplines around coding style and review.</p>
<p>The good news is that no-one is born in any of these categories and progression is actually fairly easy. Most of my life I was in category #1 (and of course, I didn’t think in those terms then – not knowing any better being one of the most noticeable features of that state).</p>
<blockquote>
<p>“I only recruit people who are in category #2 or beyond…”</p>
</blockquote>
<p>Most people with “analyst” in their job title – to my admittedly informal observation – are in the most basic of my four categories. But I think that is changing. The barriers to entry for learning R (in particular) are much less than ten years ago, with a wealth of good material online, much of it free; and much more powerful and user-friendly tools such as <a target="_blank" href="http://r4ds.had.co.nz/introduction.html">Hadley Wickham’s tidyverse</a> to make coding easier. Now for my hands-on analytical roles, I only recruit people who are in category #2 or beyond when they come to us, and I expect them to be in the best practice category #4 within a month or two of joining the team.</p>
<h2>Why naming conventions don’t cut it</h2>
<p>Here’s why that move from category #2 to #3, with the introduction of version control software, is so important. Saving multiple versions of files with different names isn’t good enough because…</p>
<h3>It doesn’t scale up to projects with many files of code</h3>
<p>A 3,000 line single script may work for a one-off project but is basically impossible to maintain, and will lead to many inefficiencies. Plus it’s difficult for multiple analysts to contribute to at once without stepping on toes. So analytical projects of even modest complexity need multiple scripts. You’ll want to separate out project-enabling infrastructure (eg functions that are going to be used multiple times, and graphics themes); data prep; analysis; and presentation / communication. All this should be held together with something like <a target="_blank" href="https://en.wikipedia.org/wiki/Makefile">make</a> or rake, or (at minimum) a master script that calls the other scripts.</p>
<p>It’s obvious how this will fall apart if you rely on re-naming your files for your version control. At the very least it will make re-creating a past state a very difficult manual task; more likely the whole system (or your understanding of it) will collapse under it’s own weight.</p>
<h3>It doesn’t scale up to projects with multiple contributors</h3>
<p>Version control lets you track who is making what additions and deletions to the code base. If things go wrong, it makes it easier to find out who broke it, and easier to reverse what they did that broke it. But more importantly, it provides a safe way for different analysts to be working simultaneously on their own versions, and then merge their changes together.</p>
<blockquote>
<p>“But if you don’t have source control, you’re going to stress out trying to get programmers to work together. Programmers have no way to know what other people did. Mistakes can’t be rolled back easily. The other neat thing about source control systems is that the source code itself is checked out on every programmer’s hard drive – I’ve never heard of a project using source control that lost a lot of code.”</p>
</blockquote>
<p><em>From Joel Sposky’s <a target="_blank" href="http://www.joelonsoftware.com/articles/fog0000000043.html">The Joel Test: 12 Steps to Better Code</a>. See also this <a target="_blank" href="http://www.coriandertech.com/2011/11/05/the-joel-test-is-antiquated/">more recent reflection from Coriander Technologies</a> on which parts of The Joel Test re less relevant now, particularly since the rise of Agile. Regardless, I often argue that the Joel Test applies to data dev teams as much as software developers. Less than 12 / 12 and you’re in a bit of trouble. Less than 9 and you’re in big trouble.</em></p>
<p>Version control software is the only way for coding projects to scale up. At least 10,000 developers, most of whom have never met eachother, work on <a target="_blank" href="http://www.zdnet.com/article/who-writes-linux-almost-10000-developers/">Linux development</a>, for example. Try keeping track of that without version control. Analytical projects don’t get this big of course, but actually many of the problems with large numbers of contributors are already there once there are three of you. And projects with three or more analysts on them are going to become much, much more common – the single academic coding by themselves is not the way of the future in data science.</p>
<p>If that’s not reason enough, remember that you’re always coding with at least two other collaborators: one or more iterations of past you, and one or more iterations of future you. Just like you write documentation for those <em>alter egos</em>, you need version control to sort out who did what, when a change was introduced and why, and how to revert it when one of the iterations of past you turns out to have broken something like the idiot you know they were.</p>
<h3>It doesn’t work with frequently maintained code bases</h3>
<p>If you write a piece of analytical code and then pull it out every couple of years to update it for changed data, you might get away with relying on naming conventions. But if you want to run it more frequently, add bits of functionality between runs, keep a production branch that works safely separate from a dev branch that doesn’t, etc. etc. – you should use the tools designed to make it possible.</p>
<h3>It doesn’t track small changes</h3>
<p>Related to the previous point, if changes are big and chunky it might be ok to have “my-analysis-final-2016.R” but then what do you call the small enhancement that comes to you in a dream the next day? Maybe you could get some naming system that works for all those small changes, but will you stick to it? And why not use software that looks after that, and gives you a visual colour-coded comparison of the differences and the commit messages explaining them?</p>
<h3>The conventions break down in a review-development cycle</h3>
<p>Have any of you seen documents with names like “my-analysis-1.1-final-post-comments-JANEsAdditions-v2-finaldraft.doc”? Of course you have. Don’t let your analytical scripts end up like that.</p>
<h3>It doesn’t support continuous integration</h3>
<p><a target="_blank" href="https://en.wikipedia.org/wiki/Continuous_integration">Continuous integration</a> (or at least very frequent integration) is the twenty first century descendent of Joel’s requirement that the team builds the whole project every day. Good analytical teams borrow the concept to frequently re-build their project end to end to be sure it all works. This applies whether you’re building an package of functionality and data for others to use (see for example <a target="_blank" href="https://travis-ci.org/ellisp/nzelect">the Travis CI build report for my nzelect R package</a>) or it’s a piece of data grooming, munging and analysis with a Shiny app and PDF at the end, like <a target="_blank" href="http://www.mbie.govt.nz/info-services/sectors-industries/tourism/tourism-research-data/international-tourism-forecasts">this example from my team at work</a>. There’s software that helps do this, and it generally assumes you’re using version control of the source code.</p>
<h2>Summing up</h2>
<p>So, if you’re coding in an analytical language like R or SAS but not using version control, give it a go. It’s easy to learn, and the few hours spent getting your head around it are justified by shifting you up a level of professional competence. Your code will be more disciplined and powerful, and easier for you to maintain, adapt, and scale up; you’ll be able to work with collaborators; you’ll get way more efficient and quick in development; and you’ll save yourself a lot of frustrations. And of course, it’s all open source and free.</p>
<blockquote>
<p>“The single academic coding by themselves is not the way of the future in data science.”</p>
</blockquote>
<p>I suspect most of my readers don’t need the message. The importance of version control is pretty widely recognised and is now one of the basic things taught in courses like the Johns Hopkins <a target="_blank" href="https://www.coursera.org/learn/data-scientists-tools">The Data Scientist’s Toolbox</a> on Coursera, and in <a target="_blank" href="http://software-carpentry.org/">software carpentry</a> and <a target="_blank" href="http://www.datacarpentry.org/">data carpentry</a> courses aimed at (previously) non-programming researchers. But it’s not yet reached all analysts and analytical teams, many of which are small and isolated from good practice. There’ll be a transition period I imagine with people like my original correspondent reluctant to embrace more collaborative approaches; but as analytics teams increase in size and expectations on them continue to grow, I think it won’t be possible to operate in the field without version control as part of the toolkit.</p>
<p><em>Note: the image associated with this post on the contents page and in social media “shares” is a screenshot from the <a target="_blank" href="https://github.com/hadley/ggplot2">GitHub page of ggplot2</a>. I just needed an image, I’m not associated with that page in any way other than as one of the millions of avid users of ggplot2…</em></p>
<p><div><div><div><div data-width="55" data-show-faces="false" data-send="true" data-layout="box_count" data-height="62" data-href="https://www.r-bloggers.com/why-you-need-version-control/"></div></div><div><a data-url="https://www.r-bloggers.com/why-you-need-version-control/" data-counturl="https://www.r-bloggers.com/why-you-need-version-control/" data-count="vertical" data-text="Why you need version control" class="twitter-share-button" data-via="rbloggers" href="https://twitter.com/share"></a></div><div></div></div><div></div></div>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="http://ellisp.github.io/blog/2016/09/16/version-control"> Peter's stats stuff - R</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 title="The R Project for Statistical Computing" rel="nofollow" href="https://www.r-project.org/">R</a> news and <a title="R tutorials" rel="nofollow" href="https://www.r-bloggers.com/?s=tutorial">tutorials</a> on topics such as: <a title="Data science" rel="nofollow" href="https://www.r-bloggers.com/?s=data%20science">Data science</a>, <a title="Big Data" rel="nofollow" href="https://www.r-bloggers.com/?s=Big%20Data">Big Data, <a title="R jobs" rel="nofollow" href="https://www.r-users.com/">R jobs</a>, visualization (<a title="ggplot and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/?s=ggplot2">ggplot2</a>, <a title="Boxplots using lattice and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/?s=boxplot">Boxplots</a>, <a title="Maps and gis" rel="nofollow" href="https://www.r-bloggers.com/?s=map">maps</a>, <a title="Animation in R" rel="nofollow" href="https://www.r-bloggers.com/?s=animation">animation</a>), programming (<a title="RStudio IDE for R" rel="nofollow" href="https://www.r-bloggers.com/?s=RStudio">RStudio</a>, <a title="Sweave and literate programming" rel="nofollow" href="https://www.r-bloggers.com/?s=sweave">Sweave</a>, <a title="LaTeX in R" rel="nofollow" href="https://www.r-bloggers.com/?s=LaTeX">LaTeX</a>, <a title="SQL and databases" rel="nofollow" href="https://www.r-bloggers.com/?s=SQL">SQL</a>, <a title="Eclipse IDE for R" rel="nofollow" href="https://www.r-bloggers.com/?s=eclipse">Eclipse</a>, <a title="git and github, Version Control System" rel="nofollow" href="https://www.r-bloggers.com/?s=git">git</a>, <a title="Large data in R using Hadoop" rel="nofollow" href="https://www.r-bloggers.com/?s=hadoop">hadoop</a>, <a title="Web Scraping of google, facebook, yahoo, twitter and more using R" rel="nofollow" href="https://www.r-bloggers.com/?s=Web+Scraping">Web Scraping</a>) statistics (<a title="Regressions and ANOVA analysis tutorials" rel="nofollow" href="https://www.r-bloggers.com/?s=regression">regression</a>, <a title="principal component analysis tutorial" rel="nofollow" href="https://www.r-bloggers.com/?s=PCA">PCA</a>, <a title="Time series" rel="nofollow" href="https://www.r-bloggers.com/?s=time+series">time series</a>, <a title="finance trading" rel="nofollow" href="https://www.r-bloggers.com/?s=trading">trading</a>) and more...
<img height="1" alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/OcoQHQUhass"></a></div>