123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214 |
- <!DOCTYPE html>
- <!-- Generated by pkgdown: do not edit by hand --><html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
- <meta charset="utf-8">
- <meta http-equiv="X-UA-Compatible" content="IE=edge">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Explore tidyverse with liftr • liftr</title>
- <!-- jquery --><script src="https://code.jquery.com/jquery-3.1.0.min.js" integrity="sha384-nrOSfDHtoPMzJHjVTdCopGqIqeYETSXhZDFyniQ8ZHcVy08QesyHcnOUpMpqnmWq" crossorigin="anonymous"></script><!-- Bootstrap --><link href="https://maxcdn.bootstrapcdn.com/bootswatch/3.3.7/flatly/bootstrap.min.css" rel="stylesheet" crossorigin="anonymous">
- <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script><!-- Font Awesome icons --><link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css" rel="stylesheet" integrity="sha384-T8Gy5hrqNKT+hzMclPo118YTQO6cYprQmhrYwIiQ/3axmI1hQomh7Ud2hPOy8SP1" crossorigin="anonymous">
- <!-- pkgdown --><link href="../pkgdown.css" rel="stylesheet">
- <script src="../jquery.sticky-kit.min.js"></script><script src="../pkgdown.js"></script><!-- mathjax --><script src="https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script><!--[if lt IE 9]>
- <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
- <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
- <![endif]--><!-- Google analytics --><script>
- (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
- (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
- m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
- })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
- ga('create', 'UA-65001771-1', 'auto');
- ga('send', 'pageview');
- </script>
- </head>
- <body>
- <div class="container template-vignette">
- <header><div class="navbar navbar-default navbar-fixed-top" role="navigation">
- <div class="container">
- <div class="navbar-header">
- <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar">
- <span class="icon-bar"></span>
- <span class="icon-bar"></span>
- <span class="icon-bar"></span>
- </button>
- <a class="navbar-brand" href="../index.html">liftr</a>
- </div>
- <div id="navbar" class="navbar-collapse collapse">
- <ul class="nav navbar-nav">
- <li>
- <a href="../index.html">
- <span class="fa fa-home fa-lg"></span>
-
- </a>
- </li>
- <li>
- <a href="../reference/index.html">Reference</a>
- </li>
- <li class="dropdown">
- <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">
- Articles
-
- <span class="caret"></span>
- </a>
- <ul class="dropdown-menu" role="menu">
- <li>
- <a href="../articles/liftr-addins.html">RStudio Addins for liftr</a>
- </li>
- <li>
- <a href="../articles/liftr-intro.html">A Quick Introduction to liftr</a>
- </li>
- <li>
- <a href="../articles/liftr-tidyverse.html">Explore tidyverse with liftr</a>
- </li>
- </ul>
- </li>
- <li>
- <a href="../news/index.html">News</a>
- </li>
- </ul>
- <ul class="nav navbar-nav navbar-right">
- <li>
- <a href="https://github.com/road2stat/liftr">
- <span class="fa fa-github fa-lg"></span>
-
- </a>
- </li>
- </ul>
- </div>
- <!--/.nav-collapse -->
- </div>
- <!--/.container -->
- </div>
- <!--/.navbar -->
-
- </header><div class="row">
- <div class="col-md-9">
- <div class="page-header toc-ignore">
- <h1>Explore tidyverse with liftr</h1>
- <h4 class="author">Nan Xiao <<a href="https://nanx.me" class="uri">https://nanx.me</a>></h4>
-
- <h4 class="date">2017-12-13</h4>
- </div>
-
-
- <div class="contents">
- <div id="introduction" class="section level1">
- <h1 class="hasAnchor">
- <a href="#introduction" class="anchor"></a>Introduction</h1>
- <p>Creating Docker images from scratch can be time and labor consuming. Fortunately, many pre-built and regularly updated Docker images for the R community are ready for use, especially when creating your own containerized R Markdown documents with liftr.</p>
- <p>Such sources of pre-built Docker images include the <a href="https://github.com/rocker-org/rocker">rocker project</a> and <a href="https://bioconductor.org/help/docker/">Bioconductor Docker containers</a>. In this article, we will use the <a href="https://hub.docker.com/r/rocker/tidyverse/">tidyverse image</a> provided by rocker. This image includes the essential tidyverse packages and devtools environment loved by many data scientists <span class="citation">(Wickham 2014)</span>. We will demonstrate how to containerize and render your tidyverse-heavy R Markdown document using Docker in only a few minutes.</p>
- </div>
- <div id="install-docker" class="section level1">
- <h1 class="hasAnchor">
- <a href="#install-docker" class="anchor"></a>Install Docker</h1>
- <p>If Docker has not been installed on your system, please use <code><a href="../reference/install_docker.html">install_docker()</a></code> and follow the guidelines to install it. After that, <code><a href="../reference/check_docker_install.html">check_docker_install()</a></code> and <code><a href="../reference/check_docker_running.html">check_docker_running()</a></code> would help you make sure that Docker has been installed and running properly.</p>
- </div>
- <div id="example-document" class="section level1">
- <h1 class="hasAnchor">
- <a href="#example-document" class="anchor"></a>Example document</h1>
- <p>Let’s create a new folder first and copy the example R Markdown document to this folder:</p>
- <div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">path =<span class="st"> </span><span class="kw">paste0</span>(<span class="st">"~/liftr-tidyverse/"</span>)
- <span class="kw">dir.create</span>(path)
- <span class="kw">file.copy</span>(<span class="kw">system.file</span>(<span class="st">"examples/liftr-tidyverse.Rmd"</span>, <span class="dt">package =</span> <span class="st">"liftr"</span>), path)
- input =<span class="st"> </span><span class="kw">paste0</span>(path, <span class="st">"liftr-tidyverse.Rmd"</span>)</code></pre></div>
- <p>If we open the R Markdown file, we will see the header section includes a <code>liftr</code> section, which defines the Docker system environment required to render this document. For our case, it is very straightforward and simple indeed:</p>
- <div class="sourceCode"><pre class="sourceCode yaml"><code class="sourceCode yaml"><span class="ot">---</span>
- <span class="fu">title:</span><span class="at"> </span><span class="st">"Explore tidyverse with liftr"</span>
- <span class="fu">author:</span><span class="at"> </span><span class="st">"Nan Xiao <<[email protected]>>"</span>
- <span class="fu">date:</span><span class="at"> </span><span class="st">"2017-12-13"</span>
- <span class="fu">output:</span>
- <span class="fu">rmarkdown:</span><span class="at">:pdf_document:</span>
- <span class="fu">toc:</span><span class="at"> true</span>
- <span class="fu">number_sections:</span><span class="at"> true</span>
- <span class="fu">liftr:</span>
- <span class="fu">from:</span><span class="at"> </span><span class="st">"rocker/tidyverse:latest"</span>
- <span class="fu">maintainer:</span><span class="at"> </span><span class="st">"Nan Xiao"</span>
- <span class="fu">email:</span><span class="at"> </span><span class="st">"[email protected]"</span>
- <span class="fu">pandoc:</span><span class="at"> false</span>
- <span class="fu">texlive:</span><span class="at"> true</span>
- <span class="fu">cran:</span>
- <span class="kw">-</span> nycflights13
- <span class="ot">---</span></code></pre></div>
- <p>Most of the fields are self-explanatory:</p>
- <ul>
- <li>Here we simply specified the latest <code>rocker/tidyverse</code> image as our base image, which would save us a lot of time creating a custom base image with all the tidyverse dependencies.</li>
- <li>The custom <code>pandoc</code> installation was not included because the tidyverse image already includes <code>pandoc</code>.</li>
- <li>We included TeXLive here since we intend to render a PDF file in the end.</li>
- <li>The CRAN data package <code>nycflights13</code> will be installed.</li>
- </ul>
- </div>
- <div id="containerize-the-document" class="section level1">
- <h1 class="hasAnchor">
- <a href="#containerize-the-document" class="anchor"></a>Containerize the document</h1>
- <p>Let’s containerize this document by generating a <code>Dockerfile</code> for it, using <code><a href="http://www.rdocumentation.org/packages/liftr/topics/lift">liftr::lift</a></code>:</p>
- <div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw"><a href="../reference/lift.html">lift</a></span>(input)</code></pre></div>
- <p>A file named <code>Dockerfile</code> will be generated under the same directory of the input RMD file. It contains the necessary commands for building the Docker container for rendering the document.</p>
- </div>
- <div id="render-the-document" class="section level1">
- <h1 class="hasAnchor">
- <a href="#render-the-document" class="anchor"></a>Render the document</h1>
- <p>We can use <code><a href="../reference/render_docker.html">render_docker()</a></code> to start the Docker container, and render the document inside it:</p>
- <div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw"><a href="../reference/render_docker.html">render_docker</a></span>(input)</code></pre></div>
- <p>Let’s view the rendered document:</p>
- <div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">browseURL</span>(<span class="kw">paste0</span>(path, <span class="st">"liftr-tidyverse.pdf"</span>))</code></pre></div>
- <p>In the last section of the rendered PDF, we will see that the session information are probably different with your current system’s information. Yes, that is because the document is completed generated by a newly built, isolated Linux system environment, using Docker.</p>
- <p>In this way, the R Markdown document gains a higher, system level reproducibility, thus easily replicable by other users who might not have the identical system and R package environment to yours. This is a good thing for team collaboration and large-scale document orchestration. The best part is, all you need to share is still the document itself, only with a few extra metadata fields.</p>
- </div>
- <div id="housekeeping" class="section level1">
- <h1 class="hasAnchor">
- <a href="#housekeeping" class="anchor"></a>Housekeeping</h1>
- <p>The Docker images stored in your system could take a few gigabytes and get larger gradually as you build more images. Let’s remove the generated Docker image to save some disk space:</p>
- <div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw"><a href="../reference/prune_image.html">prune_image</a></span>(<span class="kw">paste0</span>(path, <span class="st">"liftr-tidyverse.docker.yml"</span>))</code></pre></div>
- <p>If we do this, the Docker container will be rebuilt next time when you use <code><a href="../reference/render_docker.html">render_docker()</a></code>. If not, the image will be cached in the system and reused when compiling the document later and save some time for you.</p>
- </div>
- <div id="references" class="section level1 unnumbered">
- <h1 class="hasAnchor">
- <a href="#references" class="anchor"></a>References</h1>
- <div id="refs" class="references">
- <div id="ref-wickham2014tidy">
- <p>Wickham, Hadley. 2014. “Tidy Data.” <em>Journal of Statistical Software</em> 59 (10): 1–23.</p>
- </div>
- </div>
- </div>
- </div>
- </div>
- <div class="col-md-3 hidden-xs hidden-sm" id="sidebar">
- <div id="tocnav">
- <h2 class="hasAnchor">
- <a href="#tocnav" class="anchor"></a>Contents</h2>
- <ul class="nav nav-pills nav-stacked">
- <li><a href="#introduction">Introduction</a></li>
- <li><a href="#install-docker">Install Docker</a></li>
- <li><a href="#example-document">Example document</a></li>
- <li><a href="#containerize-the-document">Containerize the document</a></li>
- <li><a href="#render-the-document">Render the document</a></li>
- <li><a href="#housekeeping">Housekeeping</a></li>
- <li><a href="#references">References</a></li>
- </ul>
- </div>
- </div>
- </div>
- <footer><div class="copyright">
- <p>Developed by Nan Xiao.</p>
- </div>
- <div class="pkgdown">
- <p>Site built with <a href="http://hadley.github.io/pkgdown/">pkgdown</a>.</p>
- </div>
- </footer>
- </div>
- </body>
- </html>
|