<p><div><div><div><div data-width="100" data-show-faces="false" data-send="true" data-layout="button_count" data-height="21" data-href="http://www.r-bloggers.com/good-r-packages/"></div></div><div><a data-url="http://www.r-bloggers.com/good-r-packages/" data-counturl="http://www.r-bloggers.com/good-r-packages/" data-count="horizontal" data-text="Good R Packages" 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://blog.revolutionanalytics.com/2016/05/good-r-packages.html"> Revolutions</a></strong>, and kindly contributed to <a rel="nofollow" href="http://www.r-bloggers.com/">R-bloggers)</a> </div>
<div>
<p>by Joseph Rickert</p>
<p>What makes for a good R package? With over 8,000 packages up on <a target="_blank" href="https://cran.r-project.org/web/packages/">CRAN</a> the quantity of packages is clearly not an issue for R users. Developing an instinct to recognize quality, however, both requires and deserves some effort. I regularly spend time on Dirk Eddelbuettel’s <a target="_blank" href="http://dirk.eddelbuettel.com/cranberries/">CRANberries</a> site investigating new packages and monitoring changes in old favorites in order to recommend packages for inclusion in MRAN’s <a target="_blank" href="https://mran.microsoft.com/spotlight/">Package Spotlight</a> page. As a consequence, I think I’m getting a feel for quality and I believe it comes down to this: <em>A good R package clearly says what it does and then really does what it says.</em></p>
<p>It should not be surprising that documentation is the key. For an R package, the first obvious place for an author to provide quality documentation is the vignette. Hadley Wickham <a target="_blank" href="http://r-pkgs.had.co.nz/vignettes.html">writes</a>:</p>
<p>A vignette is a long-form guide to your package. . . A vignette is like a book chapter or an academic paper: it can describe the problem that your package is designed to solve, and then show the reader how to solve it. . . Vignettes are also useful if you want to explain the details of your package. For example, if you have implemented a complex statistical algorithm, you might want to describe all the details in a vignette so that users of your package can understand what’s going on under the hood, and be confident that you’ve implemented the algorithm correctly.</p>
<p>Unfortunately,  less than 25% of all R packages have vignettes!</p>
<p><a target="_blank" href="http://revolution-computing.typepad.com/.a/6a010534b1db25970b01b8d1e28742970c-pi"><img title="Hist_vignettes2" alt="Hist_vignettes2" src="http://revolution-computing.typepad.com/.a/6a010534b1db25970b01b8d1e28742970c-800wi" border="0"></a></p>
<p>As a person who is in the habit of writing, I find it astounding that anyone would do all the creative work to develop the contents of a package and then make the effort to get it through the CRAN process and release into the open source domain without taking the basic step to explain its value, and maybe even discretely sing its praises. Nevertheless, most package authors, even some who have otherwise done great work balk at writing engaging documentation.</p>
<p>Although they are not visible in the plot above, there are a few packages whose authors have made extravagant attempts at documentation. The following table lists all packages with 10 or more vignettes. </p>
<p><span>  Name         Date          Vignettes</span><br><span>1 caschrono    2014-03-21       10</span><br><span>2 catdata      2014-11-11       45</span><br><span>3 copula       2015-10-26       13</span><br><span>4 gamclass     2015-08-20       11</span><br><span>5 ggvis        2015-06-06       10</span><br><span>6 HSAUR        2015-07-28       17</span><br><span>7 HSAUR2       2015-07-28       19</span><br><span>8 HSAUR3       2015-07-29       22</span><br><span>9 Sleuth2      2016-01-08       13</span><br><span>10 Sleuth3     2016-01-08       13</span><br><span>11 tigerstats  2015-09-23       20</span></p>
<p>(Yes, <a target="_blank" href="https://mran.microsoft.com/package/catdata/">catdata</a> does really have 45 vignettes, but the package is the documentation for a book.)</p>
<p>To be fair and thorough though, I should mention that are some pretty lame vignettes out there. I sometimes do find myself putting a new package on the short list for a Spotlight evaluation just because it has a vignette, only to be disappointed when it I get around to looking at it.</p>
<p>I should also note that writing a vignette is neither the only way, nor the most sophisticated way to document an R package. Top shelf packages implementing a statistical algorithm or new computational method are often complemented up by a paper published in the <a target="_blank" href="https://www.jstatsoft.org/index">Journal of Statistical Software</a> or some other peer reviewed publication. <a target="_blank" href="https://mran.revolutionanalytics.com/package/kernlab/">kernlab</a>, for example, uses a version of its <a target="_blank" href="https://www.jstatsoft.org/index">JSS paper</a> as a <a target="_blank" href="https://mran.microsoft.com/web/packages/kernlab/vignettes/kernlab.pdf">vignette</a>. Other packages, such as <a target="_blank" href="https://mran.microsoft.com/package/statnet/">statnet</a> are backed up by informative <a target="_blank" href="http://statnet.org/">websites</a>, and it is also becoming common for packages authors to provide links to their GitHub development sites. See <a target="_blank" href="https://mran.revolutionanalytics.com/package/data.table/">data.table's</a> GitHub <a target="_blank" href="https://github.com/Rdatatable/data.table/wiki">page</a>, for example, or Dirk's Rcpp <a target="_blank" href="https://cran.r-project.org/web/packages/Rcpp/index.html">CRAN page</a> which provides links to extensive documentation listing multiple vignettes as well as multiple websites. I find it particularly convenient that the package <a target="_blank" href="https://mran.revolutionanalytics.com/web/packages/Rcpp/Rcpp.pdf">pdf</a> links to these sites and also to the supporting <a target="_blank" href="https://www.jstatsoft.org/article/view/v040i08">JSS paper</a>.</p>
<p>So, what about the other part of my definition: A good R package … really does what it says. I find that good documentation does correlate positively with good code, but beyond that the best way to make a quick assessment of the quality of a package is to see if it is included in any of the <a target="_blank" href="https://cran.r-project.org/web/views/">CRAN Task Views</a>. These are lists of packages organized and curated by experts who make heroic efforts to keep them current and comprehensive, if not complete. Amazingly, 27% of CRAN packages are listed in at least one Task View! This is higher than the percentage of packages that have vignettes. </p>
<p><a target="_blank" href="https://mran.revolutionanalytics.com/">MRAN</a> provides a lookup feature that is convenient for checking a package's quality potential. With one click you can see the names of any vignettes that may be associated with a package along with any Task Views in which it may be listed.</p>
<p> </p>
<p>  <a target="_blank" href="http://revolution-computing.typepad.com/.a/6a010534b1db25970b01b7c858c620970b-pi"><img title="Copula" alt="Copula" src="http://revolution-computing.typepad.com/.a/6a010534b1db25970b01b7c858c620970b-800wi" border="0"></a></p>
<p>Of course, the crucial step for checking quality and utility of a package is to try the package yourself. Doing this also provides an opportunity for you the user to contribute to the common good by just using the package in your work, talking about its merits, and maybe even providing constructive feedback to the author if you think that would be helpful.</p>
<p>The data for this post comes from a <a target="_blank" href="https://mran.revolutionanalytics.com/packagedata/allpackages.json">JSON file</a> available on the MRAN website. The code below was used for the post.</p>
<div>
<div>
<pre><a target="_blank" href="http://inside-r.org/r-doc/base/library"><span>library</span></a><span>(</span>jsonlite<span>)</span>
<a target="_blank" href="http://inside-r.org/r-doc/base/library"><span>library</span></a><span>(</span><a target="_blank" href="http://inside-r.org/packages/cran/ggplot2">ggplot2</a><span>)</span>
 
<span># Read in package data as JSON file and form into a data frame</span>
json_file &lt;- <span>&quot;https://mran.revolutionanalytics.com/packagedata/allpackages.json&quot;</span>
json_data &lt;- <a target="_blank" href="http://inside-r.org/r-doc/base/as.data.frame"><span>as.data.frame</span></a><span>(</span>fromJSON<span>(</span><a target="_blank" href="http://inside-r.org/r-doc/base/paste"><span>paste</span></a><span>(</span><a target="_blank" href="http://inside-r.org/r-doc/base/readLines"><span>readLines</span></a><span>(</span>json_file<span>)</span><span>,</span><a target="_blank" href="http://inside-r.org/r-doc/nlme/collapse"><span>collapse</span></a>=<span>&quot;&quot;</span><span>)</span><span>)</span><span>)</span>
 
dF &lt;- json_data<span>[</span><span>,</span><a target="_blank" href="http://inside-r.org/r-doc/base/c"><span>c</span></a><span>(</span><span>1</span><span>,</span><span>2</span><span>,</span><span>6</span><span>,</span><span>7</span><span>)</span><span>]</span>
<a target="_blank" href="http://inside-r.org/r-doc/base/names"><span>names</span></a><span>(</span>dF<span>)</span> &lt;- <a target="_blank" href="http://inside-r.org/r-doc/base/c"><span>c</span></a><span>(</span><span>&quot;Name&quot;</span><span>,</span><span>&quot;Date&quot;</span><span>,</span><span>&quot;Task_View&quot;</span><span>,</span><span>&quot;Vignettes&quot;</span><span>)</span>
dF$Vignettes &lt;- <a target="_blank" href="http://inside-r.org/r-doc/base/ifelse"><span>ifelse</span></a><span>(</span><a target="_blank" href="http://inside-r.org/r-doc/base/is.na"><span>is.na</span></a><span>(</span>dF$Vignettes<span>)</span>==<span>TRUE</span><span>,</span><span>0</span><span>,</span>dF$Vignettes<span>)</span>
dF$Task_View &lt;- <a target="_blank" href="http://inside-r.org/r-doc/base/ifelse"><span>ifelse</span></a><span>(</span><a target="_blank" href="http://inside-r.org/r-doc/base/is.na"><span>is.na</span></a><span>(</span>dF$Task_View<span>)</span>==<span>TRUE</span><span>,</span><span>&quot;None&quot;</span><span>,</span>dF$Task_View<span>)</span>
<a target="_blank" href="http://inside-r.org/r-doc/utils/head"><span>head</span></a><span>(</span>dF<span>)</span>
 
<span># Look at some summary statistics</span>
<a target="_blank" href="http://inside-r.org/r-doc/base/summary"><span>summary</span></a><span>(</span>dF$Vignettes<span>)</span>
<a target="_blank" href="http://inside-r.org/r-doc/base/table"><span>table</span></a><span>(</span>dF$Vignettes<span>)</span>
 
<span># Find number of vignettes</span>
have_vig &lt;- <a target="_blank" href="http://inside-r.org/r-doc/base/sum"><span>sum</span></a><span>(</span>dF$Vignettes><span>0</span><span>)</span>
have_vig <span>#1961</span>
 
pct_vig &lt;- have_vig / <a target="_blank" href="http://inside-r.org/r-doc/base/length"><span>length</span></a><span>(</span>dF$Vignettes<span>)</span>
pct_vig <span>#0.2353859</span>
 
<span># Find package with >= 10 Task Views</span>
dF<span>[</span>dF$Vignettes>=<span>10</span><span>,</span><span>]</span> 
 
<span># Modify data frame for printing</span>
dF10 &lt;- dF<span>[</span>dF$Vignettes>=<span>10</span><span>,</span> -<span>3</span><span>]</span>
<a target="_blank" href="http://inside-r.org/r-doc/base/row.names"><span>row.names</span></a><span>(</span>dF10<span>)</span> &lt;- <span>NULL</span>
dF10
 
<span># Plot histogram</span>
p &lt;- <a target="_blank" href="http://inside-r.org/packages/cran/ggplot">ggplot</a><span>(</span>dF<span>,</span> aes<span>(</span>x=Vignettes<span>)</span><span>)</span>
p + geom_histogram<span>(</span>binwidth=<span>1</span><span>)</span> +
  ggtitle<span>(</span><span>&quot;The sad tale but long tail of vignettes&quot;</span><span>)</span>
 
<span># Find number of packages in task views</span>
have_TV &lt;- dF<span>[</span>dF$Task_View!=<span>&quot;None&quot;</span><span>,</span><span>]</span>
pct_TV &lt;- <a target="_blank" href="http://inside-r.org/r-doc/base/dim"><span>dim</span></a><span>(</span>have_TV<span>)</span><span>[</span><span>1</span><span>]</span> / <a target="_blank" href="http://inside-r.org/r-doc/base/length"><span>length</span></a><span>(</span>dF$Vignettes<span>)</span>
pct_TV <span>#0.2724763</span></pre>
</div>
</div>
<p> </p>
</div>
<p><div><div><div><div data-width="55" data-show-faces="false" data-send="true" data-layout="box_count" data-height="62" data-href="http://www.r-bloggers.com/good-r-packages/"></div></div><div><a data-url="http://www.r-bloggers.com/good-r-packages/" data-counturl="http://www.r-bloggers.com/good-r-packages/" data-count="vertical" data-text="Good R Packages" 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://blog.revolutionanalytics.com/2016/05/good-r-packages.html"> Revolutions</a></strong>.</div>
<hr>
<a rel="nofollow" href="http://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="http://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="http://www.r-project.org/">R</a> news and <a title="R tutorials" rel="nofollow" href="http://www.r-bloggers.com/?s=tutorial">tutorials</a> on topics such as: <a title="Data science" rel="nofollow" href="http://www.r-bloggers.com/?s=data%20science">Data science</a>, <a title="Big Data" rel="nofollow" href="http://www.r-bloggers.com/?s=Big%20Data">Big Data, <a title="R jobs" rel="nofollow" href="http://www.r-users.com/">R jobs</a>, visualization (<a title="ggplot and ggplot2 tutorials" rel="nofollow" href="http://www.r-bloggers.com/?s=ggplot2">ggplot2</a>, <a title="Boxplots using lattice and ggplot2 tutorials" rel="nofollow" href="http://www.r-bloggers.com/?s=boxplot">Boxplots</a>, <a title="Maps and gis" rel="nofollow" href="http://www.r-bloggers.com/?s=map">maps</a>, <a title="Animation in R" rel="nofollow" href="http://www.r-bloggers.com/?s=animation">animation</a>), programming (<a title="RStudio IDE for R" rel="nofollow" href="http://www.r-bloggers.com/?s=RStudio">RStudio</a>, <a title="Sweave and literate programming" rel="nofollow" href="http://www.r-bloggers.com/?s=sweave">Sweave</a>, <a title="LaTeX in R" rel="nofollow" href="http://www.r-bloggers.com/?s=LaTeX">LaTeX</a>, <a title="SQL and databases" rel="nofollow" href="http://www.r-bloggers.com/?s=SQL">SQL</a>, <a title="Eclipse IDE for R" rel="nofollow" href="http://www.r-bloggers.com/?s=eclipse">Eclipse</a>, <a title="git and github, Version Control System" rel="nofollow" href="http://www.r-bloggers.com/?s=git">git</a>, <a title="Large data in R using Hadoop" rel="nofollow" href="http://www.r-bloggers.com/?s=hadoop">hadoop</a>, <a title="Web Scraping of google, facebook, yahoo, twitter and more using R" rel="nofollow" href="http://www.r-bloggers.com/?s=Web+Scraping">Web Scraping</a>) statistics (<a title="Regressions and ANOVA analysis tutorials" rel="nofollow" href="http://www.r-bloggers.com/?s=regression">regression</a>, <a title="principal component analysis tutorial" rel="nofollow" href="http://www.r-bloggers.com/?s=PCA">PCA</a>, <a title="Time series" rel="nofollow" href="http://www.r-bloggers.com/?s=time+series">time series</a>, <a title="finance trading" rel="nofollow" href="http://www.r-bloggers.com/?s=trading">trading</a>) and more...
<img height="1" alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/c0pvRTq3Vm0"></a></div>