<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/new-features-in-the-checkpoint-package-version-0-4-0/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://blog.revolutionanalytics.com/2017/04/checkpoint-new-features.html"> Revolutions</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<div>
<p><em>by Andrie de Vries</em></p>
<p>In 2014 we introduced the <a target="_blank" rel="nofollow" href="https://mran.microsoft.com/documents/rro/reproducibility/#timemachine">checkpoint</a> package for reproducible research. This package makes it easy to use R package versions that existed on CRAN at a given date in the past, and to use varying package versions with different projects. Previous blog posts include:</p>
<ul>
<li><a target="_blank" rel="nofollow" href="http://blog.revolutionanalytics.com/2014/10/introducing-rrt.html">Introducing the Reproducible R Toolkit and the checkpoint package</a></li>
<li><span><a target="_blank" rel="nofollow" href="http://blog.revolutionanalytics.com/2015/02/an-update-to-the-checkpoint-package.html">An update to the checkpoint package</a></span></li>
<li><span><a target="_blank" rel="nofollow" href="http://blog.revolutionanalytics.com/2015/09/new-features-in-checkpoint-v0315-now-on-cran.html">New features in checkpoint v0.3.15 now on CRAN</a></span></li>
</ul>
<p><span>On April 12, 2017, we published version 0.4.0 of <a target="_blank" rel="nofollow" href="https://cran.r-project.org/package=checkpoint">checkpoint to CRAN</a>.</span></p>
<p>The <code>checkpoint()</code> function enables reproducible research by managing your R package versions. These packages are downloaded into a local <code>.checkpoint</code> folder. If you use <code>checkpoint()</code> for many projects, these local packages can consume some storage space, and this update introduces functions to manage your snapshots. In this post I review:</p>
<ul>
<li>Managing local archives:
<ul>
<li><code>checkpointArchives()</code>: list checkpoint archives on disk.</li>
<li><code>checkpointRemove()</code>: remove checkpoint archive from disk.</li>
<li><code>getAccessDate()</code>: returns the date the snapshot was last accessed.</li>
</ul>
</li>
<li>Other:
<ul>
<li><code>unCheckpoint()</code>: reset .libPaths to the user library to undo the effect of checkpoint().</li>
</ul>
</li>
</ul>
<h2>Setting up an example project</h2>
<p>For illustration, set up a script referencing a single package:</p>
<pre><code>library(MASS)
hist(islands)
truehist(islands)
</code></pre>
<p>Next, create the checkpoint:</p>
<pre><code>dir.create(file.path(tempdir(), &quot;.checkpoint&quot;), recursive = TRUE)
## Create a checkpoint by specifying a snapshot date
library(checkpoint)
checkpoint(&quot;2015-04-26&quot;, project = tempdir(), checkpointLocation = tempdir())
</code></pre>
<h2>Working with checkpoint archive snapshots</h2>
<p>You can query the available snapshots on disk using the <code>checkpointArchives()</code> function. This returns a vector of snapshot folders.</p>
<pre><code># List checkpoint archives on disk.
checkpointArchives(tempdir())
</code></pre>
<pre><code>## [1] &quot;2015-04-26&quot;
</code></pre>
<p>You can get the full paths by including the argument <code>full.names=TRUE</code>:</p>
<pre><code>checkpointArchives(tempdir(), full.names = TRUE)
</code></pre>
<pre><code>## [1] &quot;C:/Users/adevries/AppData/Local/Temp/RtmpcnciXd/.checkpoint/2015-04-26&quot;
</code></pre>
<h2>Working with access dates</h2>
<p>Every time you use <code>checkpoint()</code> the function places a small marker in the snapshot archive with the access date. In this way you can track when was the last time you actually used the snapshot archive.</p>
<pre><code># Returns the date the snapshot was last accessed.
getAccessDate(tempdir())
</code></pre>
<pre><code>## C:/Users/adevries/AppData/Local/Temp/RtmpcnciXd/.checkpoint/2015-04-26 
##                                                           &quot;2017-04-12&quot;
</code></pre>
<h2>Removing a snapshot from local disk</h2>
<p>Since the date of last access is tracked, you can use this to manage your checkpoint archives. The function <code>checkpointRemove()</code> will delete archives from disk. You can use this function in multiple ways. For example, specify a specific archive to remove:</p>
<pre><code># Remove singe checkpoint archive from disk.
checkpointRemove(&quot;2015-04-26&quot;)
</code></pre>
<p>You can also remove a range of snapshot archives older (or more recent) than a snapshot date</p>
<pre><code># Remove range of checkpoint archives from disk.
checkpointRemove(&quot;2015-04-26&quot;, allSinceSnapshot = TRUE)
checkpointRemove(&quot;2015-04-26&quot;, allUntilSnapshot =  = TRUE)
</code></pre>
<p>Finally, you can remove all snapshot archives that have not been accessed since a given date:</p>
<pre><code># Remove snapshot archives that have not been used recently
checkpointRemove(&quot;2015-04-26&quot;, notUsedSince = TRUE)
</code></pre>
<h2>Reading the checkpoint log file</h2>
<p>One of the side effects of <code>checkpoint()</code> is to create a log file that contains information about packages that get downloaded, as well as the download size. This file is stored in the checkpoint root folder, and is a csv file with column names, so you can read this with your favourite R function or other tools.</p>
<pre><code>dir(file.path(tempdir(), &quot;.checkpoint&quot;))
</code></pre>
<pre><code>## [1] &quot;2015-04-26&quot;         &quot;checkpoint_log.csv&quot; &quot;R-3.3.3&quot;
</code></pre>
<p>Inspect the log file:</p>
<pre><code>log_file </code></pre>
<pre><code>##             timestamp snapshotDate  pkg   bytes
## 1 2017-04-12 15:05:12   2015-04-26 MASS 1084392
</code></pre>
<h2>Resetting the checkpoint</h2>
<p>In older versions of <code>checkpoint()</code> the only way to reset the effect of <code>checkpoint()</code> was to restart your R session. In v0.3.20 and above, you can use the function <code>unCheckpoint()</code>. This will reset your <code>.libPaths</code> to the user folder.</p>
<pre><code>.libPaths()
</code></pre>
<pre><code>## [1] &quot;C:/Users/adevries/AppData/Local/Temp/RtmpcnciXd/.checkpoint/2015-04-26/lib/x86_64-w64-mingw32/3.3.3&quot;
## [2] &quot;C:/Users/adevries/AppData/Local/Temp/RtmpcnciXd/.checkpoint/R-3.3.3&quot;                                
## [3] &quot;C:/R/R-33~1.3/library&quot;
</code></pre>
<pre>Now use `unCheckpoint()` to reset your library paths</pre>
<pre><code># Note this is still experimental
unCheckpoint()
.libPaths()
</code></pre>
<pre><code>## [1] &quot;C:\\Users\\adevries\\Documents\\R\\win-library&quot;
## [2] &quot;C:/R/R-33~1.3/library&quot;
</code></pre>
<h2>How to obtain and use checkpoint</h2>
<p>Version 0.4.0 of the checkpoint package is available on CRAN now, so you can install it with:</p>
<p><code>install.packages(&quot;checkpoint&quot;, repos=&quot;https://cloud.r-project.org&quot;)</code></p>
<p>The above command works both for CRAN R, and also for Microsoft R Open (which comes bundled with an older version of checkpoint). For more information on checkpoint, see the vignette <a target="_blank" rel="nofollow" href="https://mran.microsoft.com/web/packages/checkpoint/vignettes/checkpoint.html">Using checkpoint for reproducible research</a><em>.</em></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/checkpoint-new-features.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/umsC61nvh-w"></a></div>