More minor page count tweaks & fixes

And re-convert with latest htmlbook
This commit is contained in:
Hadley Wickham
2023-01-26 10:36:07 -06:00
parent d9afa135fc
commit aa9d72a7c6
38 changed files with 838 additions and 1093 deletions

View File

@@ -50,7 +50,7 @@ flights3 <- summarize(flight2,
<section id="magrittr-and-the-pipe" data-type="sect1">
<h1>
magrittr and the<code>%&gt;%</code> pipe</h1>
magrittr and the %&gt;% pipe</h1>
<p>If youve been using the tidyverse for a while, you might be familiar with the <code>%&gt;%</code> pipe provided by the <strong>magrittr</strong> package. The magrittr package is included in the core tidyverse, so you can use <code>%&gt;%</code> whenever you load the tidyverse:</p>
<div class="cell">
<pre data-type="programlisting" data-code-language="r">library(tidyverse)
@@ -70,7 +70,7 @@ mtcars %&gt;%
<section id="vs." data-type="sect1">
<h1>
<code>|&gt;</code> vs. <code>%&gt;%</code>
|&gt; vs. %&gt;%
</h1>
<p>While <code>|&gt;</code> and <code>%&gt;%</code> behave identically for simple cases, there are a few crucial differences. These are most likely to affect you if youre a long-term user of <code>%&gt;%</code> who has taken advantage of some of the more advanced features. But theyre still good to know about even if youve never used <code>%&gt;%</code> because youre likely to encounter some of them when reading wild-caught code.</p>
<ul><li><p>By default, the pipe passes the object on its left-hand side to the first argument of the function on the right-hand side. <code>%&gt;%</code> allows you to change the placement with a <code>.</code> placeholder. For example, <code>x %&gt;% f(1)</code> is equivalent to <code>f(x, 1)</code> but <code>x %&gt;% f(1, .)</code> is equivalent to <code>f(1, x)</code>. R 4.2.0 added a <code>_</code> placeholder to the base pipe, with one additional restriction: the argument has to be named. For example, <code>x |&gt; f(1, y = _)</code> is equivalent to <code>f(1, y = x)</code>.</p></li>
@@ -89,7 +89,7 @@ mtcars %&gt;%
<section id="vs" data-type="sect1">
<h1>
<code>|&gt;</code> vs <code>+</code>
|&gt; vs +
</h1>
<p>Sometimes well turn the end of a data transformation pipeline into a plot. Watch for the transition from <code>|&gt;</code> to <code>+</code>. We wish this transition wasnt necessary, but unfortunately, ggplot2 was created before the pipe was discovered.</p>
<div class="cell">
@@ -100,7 +100,7 @@ mtcars %&gt;%
</div>
</section>
<section id="summary" data-type="sect1">
<section id="workflow-pipes-summary" data-type="sect1">
<h1>
Summary</h1>
<p>In this chapter, youve learned more about the pipe: why we recommend it and some of the history that lead to <code>|&gt;</code>. The pipe is important because youll use it again and again throughout your analysis, but hopefully, it will quickly become invisible, and your fingers will type it (or use the keyboard shortcut) without your brain having to think too much about it.</p>