<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/whats-in-our-internal-chaimagic-package-at-work/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://maelle.github.io/2017/07/22/chaimagic/"> Maëlle</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>At my day job I’m a data manager and statistician for an epidemiology project called <a rel="nofollow" href="http://www.chaiproject.org/" target="_blank">CHAI</a> lead by <a rel="nofollow" href="https://twitter.com/cathryn_tonne" target="_blank">Cathryn Tonne</a>. CHAI means “Cardio-vascular health effects of air pollution in Telangana, India” and you can find more about it in <a rel="nofollow" href="http://www.sciencedirect.com/science/article/pii/S1438463917301876" target="_blank">our recently published protocol paper </a>. At <a rel="nofollow" href="http://www.isglobal.org/" target="_blank">my institute</a> you could also find the <a rel="nofollow" href="http://www.pastaproject.eu/home/" target="_blank">PASTA</a> and <a rel="nofollow" href="http://www.tapas-program.org/" target="_blank">TAPAS</a> projects so apparently epidemiologists are good at naming things, or obsessed with food… But back to CHAI! This week Sean Lopp from RStudio wrote an <a rel="nofollow" href="https://rviews.rstudio.com/2017/07/19/supporting-corporate-r-user-groups/" target="_blank">interesting blog post</a> about internal packages. I liked reading it and feeling good because we do have an internal R package for CHAI! In this blog post, I’ll explain what’s in there, in the hope of maybe providing inspiration for your own internal package!</p>
<p><img alt="" src="https://i2.wp.com/maelle.github.io/figure/source/2017-07-22-chaimagic/chaiteam_barcelona.jpg?w=456" data-recalc-dims="1"></p>
<p>As posted <a rel="nofollow" href="https://twitter.com/chaiproject/status/832330667954315264" target="_blank">in this tweet</a>, this pic represents the Barcelona contingent of CHAI, a really nice group to work with! We have other colleagues in India obviously, but also in the US.</p>
<p><span></span></p>
<h1>The birth of <code>chaimagic</code>: help for data wrangling</h1>
<p><em>Note: part of this post was submitted as an abstract for the useR! conference in Brussels, for which I received feedback from my whole team, as well as from <a rel="nofollow" href="https://twitter.com/fmic_" target="_blank">François Michonneau</a>, <a rel="nofollow" href="https://twitter.com/dirk_sch" target="_blank">Dirk Schumacher</a> and <a rel="nofollow" href="https://twitter.com/jent103" target="_blank">Jennifer Thompson</a>. Thanks a lot! I got to present a lightning talk about <a rel="nofollow" href="https://github.com/ropensci/rtimicropem" target="_blank"><code>rtimicropem</code></a> instead.</em></p>
<p>Right from the beginning of my time here in October 2015 I had quite a lot of data to clean, which I started doing in R of course. One task in particular was parsing filenames because those were informative in our project, containing for instance a date and a participant ID. I wrote a function for that, <code>batch_parse_filenames</code>, which parses all filenames in a vector and returns a list composed of two data.frames: one with the information contained in the filename (e.g. participant ID, date of sampling) and one with possible parsing mistakes (e.g. a nonexistent ID) and an informative message. It was a very useful function, and I packaged it up together with the data containing the participant IDs for instance. This was the beginning of an internal package!</p>
<p>I decided to call it <code>chaimagic</code> because it sounded cool, and this despite knowing that there’s absolutely no magic in the code I write.</p>
<h1>The growth of <code>chaimagic</code>: support for data analysis</h1>
<p><code>chaimagic</code> evolved with helper functions for analysis, e.g. a function returning the season in India from a date (e.g. monsoon, winter), or functions for common operations on variables from our questionnaire data. <code>chaimagic</code> also got <a rel="nofollow" href="https://twitter.com/MilaCarles" target="_blank">one more contributor</a>.</p>
<p><code>chaimagic</code> also contains a <code>Shiny</code> dashboard for exploring personal monitoring data that were collected in the project: one selects a participant-day and gets interactive <code>leaflet</code> and <code>rbokeh</code> plots of GPS, air quality, and time-activity data from questionnaires and wearable cameras. I told my boss that the dashboard was brought to us by the <a rel="nofollow" href="https://en.wikipedia.org/wiki/Biblical_Magi" target="_blank">biblical Magi</a> but maybe I helped them, who knows.</p>
<h1>The maturity of <code>chaimagic</code>: serving scientific communication</h1>
<p>Now, our package also supports scientific communication thanks to an <code>RMarkdown</code> template for internal reports which fostered reproducibility of analyses by making the use of <code>RMarkdown</code> even more appealing. Having an <code>RMarkdown</code> template also supports consistent branding, which is discussed in the RStudio blog post.</p>
<p><code>chaimagic</code> also includes a function returning affiliation information for any possible collaborator we have; and a function returning the agreed-upon acknowledgement sentences to be put in each manuscript. These are pieces of information we can be very happy not to have to go look for in a folder somewhere, we can get them right without leaving R!</p>
<h1>Why is <code>chaimagic</code> a really cool package?</h1>
<p><code>chaimagic</code> has been a valuable tool for the work of two statisticians/data managers, one GIS technician, one post-doc and one PhD student. Discussing its development and using it was an occasion to share our R joy, thus fostering best practices in scientific computing in our project. Why use Stata or other statistical softwares when you have such a nice internal R package? We found that even if our package served a small team of users, an R package provided a robust infrastructure to ensure that everyone was using the same code and R coding best practices in our team.</p>
<p><img alt="" src="https://i0.wp.com/maelle.github.io/figure/source/2017-07-22-chaimagic/chaimagic.jpg?w=456" data-recalc-dims="1"></p>
<p>So this is very good… but we all know from e.g. <a rel="nofollow" href="https://twitter.com/i/web/status/855422698230599680" target="_blank">Airbnb</a> (see also <a rel="nofollow" href="https://medium.com/airbnb-engineering/using-r-packages-and-education-to-scale-data-science-at-airbnb-906faa58e12d" target="_blank">this post</a> about Airbnb and R) that <em>stickers</em> are a very important aspect of an internal R package. I was over the moon when <a rel="nofollow" href="https://twitter.com/MilaCarles" target="_blank">my colleague Carles</a> handed me these fantastic <code>chaimagic</code> stickers! He used <a rel="nofollow" href="https://github.com/GuangchuangYu/hexSticker" target="_blank">the <code>hexSticker</code> package</a>. I’ll leave the team in September after everyone’s vacations, and this piece of art was the goodbye present I received at my goodbye lunch. Doesn’t it make our internal package completely cool now?</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="http://maelle.github.io/2017/07/22/chaimagic/"> Maëlle</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/Zblc2O1I5lo" height="1"></a></div>