<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/using-checkpoint-with-knitr-and-rstudio/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://blog.revolutionanalytics.com/2017/04/using-checkpoint-with-knitr-and-rstudio.html"> Revolutions</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<div>
<p>The <a target="_blank" rel="nofollow" href="https://yihui.name/knitr/">knitr package</a> by Yihui Xie is a wonderful tool for reproducible data science. I especially like using it with <a target="_blank" rel="nofollow" href="http://rmarkdown.rstudio.com/">R Markdown</a> documents, where with some simple markup in an easy-to-read document I can easily combine R code and narrative text to generate an attractive document with words, tables and pictures in HTML, PDF or Word format. Say, something like this:</p>
<p><a target="_blank" rel="nofollow" href="http://revolution-computing.typepad.com/.a/6a010534b1db25970b01b8d27be03c970c-pi"><img title="Weather-report" alt="Weather-report" src="http://revolution-computing.typepad.com/.a/6a010534b1db25970b01b8d27be03c970c-800wi" border="0"></a></p>
<p>In that document, the numerical weather records and the chart were generated by R,  combined into a document using R Markdown, and then generated as a word file with <code>knitr</code>. (You can find the R Markdown file to generate that report, and the R script to download the data, in my <a target="_blank" rel="nofollow" href="https://github.com/revodavid/weather-report">weather-report repository</a>.)</p>
<p>Another useful tool for reproducible data science is the <a target="_blank" rel="nofollow" href="https://mran.microsoft.com/package/checkpoint/">checkpoint package</a>. It helps you manage the ever-changing ecosystem of R packages on CRAN, by making it easy to &quot;lock in&quot; specific versions of R packages. With a single call to the <a target="_blank" rel="nofollow" href="https://www.rdocumentation.org/packages/checkpoint/versions/0.4.0/topics/checkpoint">checkpoint function</a> — say <code>checkpoint(&quot;2017-04-25&quot;)</code>, for April 25, 2017 — you can automatically find all the packages used by your current R project (i.e. the current folder) and install them <em>as they used to be</em> on the specified date. A colleague or collaborator can use the same script to get the same versions too, and so be confident of reproducing your results without having to worry a newer package version may have affected the results. By the way, those package versions get installed in a special folder (<code>.checkpoint</code>, in your home directory), so they won't change the results of any other R projects, either. </p>
<p>RStudio includes a very useful tool for working with R Markdown and <code>knitr</code>: you can press the &quot;Knit&quot; toolbar button to process the document with a single click. For that to work, it does require certain R packages to be available for use behind the scenes. In normal circumstances RStudio will offer to install them, but the process doesn't work when a checkpoint folder is active. A simple workaround is to include a file in the same folder (I call mine <code>knitr-packages.R</code>) with the following lines:</p>
<pre>library(&quot;formatR&quot;)
library(&quot;htmltools&quot;)
library(&quot;caTools&quot;)
library(&quot;bitops&quot;)
library(&quot;base64enc&quot;)
library(&quot;rprojroot&quot;)
library(&quot;rmarkdown&quot;)
library(&quot;evaluate&quot;)
library(&quot;stringi&quot;)
</pre>
<p>Although you never run that file directly, the checkpoint process will discover it and ensure the necessary packages are installed for RStudio to perform its magic. (In my tests this works with recent versions of RStudio including the latest, 1.0.143). All you need to do is make sure you run <code>checkpoint</code> from the R command line (just press Control-ENTER on the corresponding line in the <code>.Rmd</code> file) before attempting to knit. Simple!</p>
</div>
<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://blog.revolutionanalytics.com/2017/04/using-checkpoint-with-knitr-and-rstudio.html"> Revolutions</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/search/tutorial">tutorials</a> on topics such as: <a title="Data science" rel="nofollow" href="https://www.r-bloggers.com/search/data%20science">Data science</a>, <a title="Big Data" rel="nofollow" href="https://www.r-bloggers.com/search/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/search/ggplot2">ggplot2</a>, <a title="Boxplots using lattice and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/boxplot">Boxplots</a>, <a title="Maps and gis" rel="nofollow" href="https://www.r-bloggers.com/search/map">maps</a>, <a title="Animation in R" rel="nofollow" href="https://www.r-bloggers.com/search/animation">animation</a>), programming (<a title="RStudio IDE for R" rel="nofollow" href="https://www.r-bloggers.com/search/RStudio">RStudio</a>, <a title="Sweave and literate programming" rel="nofollow" href="https://www.r-bloggers.com/search/sweave">Sweave</a>, <a title="LaTeX in R" rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX">LaTeX</a>, <a title="SQL and databases" rel="nofollow" href="https://www.r-bloggers.com/search/SQL">SQL</a>, <a title="Eclipse IDE for R" rel="nofollow" href="https://www.r-bloggers.com/search/eclipse">Eclipse</a>, <a title="git and github, Version Control System" rel="nofollow" href="https://www.r-bloggers.com/search/git">git</a>, <a title="Large data in R using Hadoop" rel="nofollow" href="https://www.r-bloggers.com/search/hadoop">hadoop</a>, <a title="Web Scraping of google, facebook, yahoo, twitter and more using R" rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping">Web Scraping</a>) statistics (<a title="Regressions and ANOVA analysis tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/regression">regression</a>, <a title="principal component analysis tutorial" rel="nofollow" href="https://www.r-bloggers.com/search/PCA">PCA</a>, <a title="Time series" rel="nofollow" href="https://www.r-bloggers.com/search/time+series">time series</a>, <a title="finance trading" rel="nofollow" href="https://www.r-bloggers.com/search/trading">trading</a>) and more...
<img height="1" alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/-BsSv44Fm20"></a></div>