<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/submitting-your-first-package-to-cran-my-experience/"></div></div><div><a data-url="http://www.r-bloggers.com/submitting-your-first-package-to-cran-my-experience/" data-counturl="http://www.r-bloggers.com/submitting-your-first-package-to-cran-my-experience/" data-count="horizontal" data-text="Submitting your first package to CRAN, my experience" 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="https://rmhogervorst.github.io/cleancode/blog/2016/07/09/submtting-to-cran-first-experience.html"> Clean Code</a></strong>, and kindly contributed to <a rel="nofollow" href="http://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>I recently published my first R package to The Comprehensive R Archive Network (CRAN). It was very exciting and also quite easy. Let me walk you through my process.</p>
<p>First a description of my brand new package: badgecreatr, then a description of steps to take for submission.</p>
<h1>Package description</h1>
<p>When you go around github looking at projects you often see these interesting images in the readme<br>
<a target="_blank" href="https://travis-ci.org/hadley/ggplot2"><img alt="Build Status" src="https://travis-ci.org/hadley/ggplot2.svg?branch=master"></a><br>
<a target="_blank" href="http://cran.r-project.org/package=ggplot2"><img alt="CRAN_Status_Badge" src="http://www.r-pkg.org/badges/version/ggplot2"></a></p>
<p>The ones you see above are from <a target="_blank" href="https://github.com/hadley/ggplot2">ggplot2</a>.</p>
<p>What are these? These are what we call badges or shields and they are often actively generated to indicate if software is actually working or not.</p>
<table>
<tbody>
<tr>
<td>Travis-ci, a continous integration service, creates the first one: the one that says build</td>
<td>passing. Everytime a new commit is pushed to Github a new version of the package will be build and tested. Of that test passes without problem the badge will remain green, but if the latest build fails, the green part will turn red like so <a target="_blank" href="https://travis-ci.org/RMHogervorst/badgecreatr"><img alt="Build Status" src="https://travis-ci.org/RMHogervorst/badgecreatr.svg?branch=develop"></a> &lt;- this is my develop branch of badgecreatr that fails while I write this. It could turn green if your read this later on.</td>
</tr>
</tbody>
</table>
<p>The point of these badges is that they quickly signal some quality aspects of your package to new users. I think these badges are incredibly useful, but I found it tedious to copy them to every new project I had, with some small tweaks for different packages <em>(I’m making this a big deal but I have only build 3 packages)</em>. Since you will use almost the same badges for many projects I thought it would be interesting to create a package that would copy them in your readme file with one command.<br>
I was not the first one with this idea, someone created the briljant badgerbadgerbadger which does the same thing for ruby on rails projects.</p>
<p>After some thoughts I decided to submit it to CRAN so that people can download it from within R without the use of devtools. So that was the why.</p>
<h1>Why would you submit a package to CRAN?</h1>
<p>The main advantage to getting your package on CRAN is that it will be easier for users to install (with install.packages). Your package will also be tested daily on multiple systems <sup><a target="_blank" href="https://rmhogervorst.github.io/cleancode/blog/2016/07/09/submtting-to-cran-first-experience.html#fn:1">1</a></sup>.</p>
<h1>How do you submit a package to CRAN?</h1>
<p>Well, the good people of CRAN have put it on the bottom of their <a target="_blank" href="https://cran.r-project.org/">main page</a>:</p>
<blockquote>
<p>To “submit” a package to CRAN, check that your submission meets the CRAN Repository Policy and then use the web form.</p>
</blockquote>
<p>Mainly you need to run r cmd-check on your package and make sure there are no warnings, and no notes. Or if there are notes, you have to explain them to the people of CRAN. So what does r-cmd-check actually do? It checks if your package can be build and installed and removed without problems, it checks for common problems in naming and if accurate documentation is provided. In other words, it checks if your package will play nice with R and possible other packages, and if people can actually read what you said about your functions in the package. r-cmd-check also checks if your DESCRIPTION and NAMESPACE files are correctly formatted.</p>
<p>You also have to do some effort to check if your package will work on other systems (solaris, FreeBSD, Linux, Windows, MacOS, more?). Since I work on a windows computer, I know it works on my computer. But since I push all my code to Github, and I use Travis-CI, after each commit the entire package is checked on linux (or more, I could even put several mac OS versions in the test I believe).</p>
<p>Furthermore I checked the functionality of most of the code with unit tests. So I was pretty sure it worked on all systems, also because I haven’t used complicated programs that could differ in systems.</p>
<p>The submission process is quite easy, you have to give your name, your email and then you can add your package (the tarball). It is a simple point and click form.</p>
<p>The website reads a part of your package, you have to check if the information is correct. Then you have to promise that you read the information and you hit submit.</p>
<h1>What happens after I submit a package?</h1>
<p>You receive a confirmation mail with everything you typed in the website.<br>
And someone looks over the submission to see if you missed something and if the package works.</p>
<p>I recieved an e-mail back (really fast!), to tell me that I mistyped some things (too bad that devtools or R-cmd-check doesn’t check for these things).<br>
I was very excited and quickly did a resubmission (which is identical to a first submission, but I explained what I changed according to their comments )</p>
<p>Things that I should have done that I forgot or didn’t notice:</p>
<ul>
<li>single quote software names so ‘Windows 8.1’</li>
<li>write R and CRAN with caps, not small letters</li>
<li>I wrote github, projectstatus, travis, rmd etc which should have been:</li>
<li>‘Github’, Projectstatus, ‘Travis-CI’ etc.</li>
<li>linked to a URL that didn’t exist yet</li>
<li>used a link with http, should have been https</li>
</ul>
<p>That was it, it took me 2 rounds but then it was finished, I received an email with: “on CRAN now. Best (name of the reviewer)”. that’s it.</p>
<p>And it’s on CRAN now: <a target="_blank" href="https://cran.r-project.org/web/packages/badgecreatr/index.html">https://cran.r-project.org/web/packages/badgecreatr/index.html</a></p>
<h2>General remarks</h2>
<p>CRAN submission used to be really hard, you had to manually write all the documentation in a seperate file, had to hand check everything, you had to search for computers to test your package on, etc. But with devtools and the excellent manuals online, starting and building a package is really easy. The final step of submission takes almost no work if you followed best practices beforehand.</p>
<h2>References:</h2>
<p>I had a lot of help from the following sources about writing r packages:</p>
<ul>
<li>a very short but extremely useful example of writing packages by Hillary Parker <a target="_blank" href="https://hilaryparker.com/2014/04/29/writing-an-r-package-from-scratch/">https://hilaryparker.com/2014/04/29/writing-an-r-package-from-scratch/</a></li>
<li>Hadley Wickham’s book about writing packages <a target="_blank" href="http://r-pkgs.had.co.nz/">http://r-pkgs.had.co.nz/</a></li>
<li>Karl Broman about writing packages <a target="_blank" href="http://kbroman.org/pkg_primer/">http://kbroman.org/pkg_primer/</a></li>
<li>You actually have to search for things in the policies, which is a bit dense, but quite ok. <a target="_blank" href="https://cran.r-project.org/web/packages/policies.html">https://cran.r-project.org/web/packages/policies.html</a></li>
<li>the ropensci organisation has some excellent advise on writing packages <a target="_blank" href="https://github.com/ropensci/packaging_guide">https://github.com/ropensci/packaging_guide</a></li>
</ul>
<h2>Notes</h2>
<div>
<ol>
<li>
<p>This I outright copied from Karl Broman found here <a target="_blank" href="http://kbroman.org/pkg_primer/pages/cran.html">http://kbroman.org/pkg_primer/pages/cran.html</a> <a target="_blank" href="https://rmhogervorst.github.io/cleancode/blog/2016/07/09/submtting-to-cran-first-experience.html#fnref:1">↩</a></p>
</li>
</ol>
</div>
<p><a target="_blank" href="https://rmhogervorst.github.io/cleancode/blog/2016/07/09/submtting-to-cran-first-experience.html">Submitting your first package to CRAN, my experience</a> was originally published by at <a target="_blank" href="https://rmhogervorst.github.io/cleancode">Clean Code</a> on July 09, 2016.</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="http://www.r-bloggers.com/submitting-your-first-package-to-cran-my-experience/"></div></div><div><a data-url="http://www.r-bloggers.com/submitting-your-first-package-to-cran-my-experience/" data-counturl="http://www.r-bloggers.com/submitting-your-first-package-to-cran-my-experience/" data-count="vertical" data-text="Submitting your first package to CRAN, my experience" 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="https://rmhogervorst.github.io/cleancode/blog/2016/07/09/submtting-to-cran-first-experience.html"> Clean Code</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/sptcbsyjeS0"></a></div>