More minor page count tweaks & fixes
And re-convert with latest htmlbook
This commit is contained in:
@@ -50,7 +50,7 @@ flights3 <- summarize(flight2,
|
||||
|
||||
<section id="magrittr-and-the-pipe" data-type="sect1">
|
||||
<h1>
|
||||
magrittr and the<code>%>%</code> pipe</h1>
|
||||
magrittr and the %>% pipe</h1>
|
||||
<p>If you’ve been using the tidyverse for a while, you might be familiar with the <code>%>%</code> pipe provided by the <strong>magrittr</strong> package. The magrittr package is included in the core tidyverse, so you can use <code>%>%</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 %>%
|
||||
|
||||
<section id="vs." data-type="sect1">
|
||||
<h1>
|
||||
<code>|></code> vs. <code>%>%</code>
|
||||
|> vs. %>%
|
||||
</h1>
|
||||
<p>While <code>|></code> and <code>%>%</code> behave identically for simple cases, there are a few crucial differences. These are most likely to affect you if you’re a long-term user of <code>%>%</code> who has taken advantage of some of the more advanced features. But they’re still good to know about even if you’ve never used <code>%>%</code> because you’re 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>%>%</code> allows you to change the placement with a <code>.</code> placeholder. For example, <code>x %>% f(1)</code> is equivalent to <code>f(x, 1)</code> but <code>x %>% 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 |> f(1, y = _)</code> is equivalent to <code>f(1, y = x)</code>.</p></li>
|
||||
@@ -89,7 +89,7 @@ mtcars %>%
|
||||
|
||||
<section id="vs" data-type="sect1">
|
||||
<h1>
|
||||
<code>|></code> vs <code>+</code>
|
||||
|> vs +
|
||||
</h1>
|
||||
<p>Sometimes we’ll turn the end of a data transformation pipeline into a plot. Watch for the transition from <code>|></code> to <code>+</code>. We wish this transition wasn’t necessary, but unfortunately, ggplot2 was created before the pipe was discovered.</p>
|
||||
<div class="cell">
|
||||
@@ -100,7 +100,7 @@ mtcars %>%
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section id="summary" data-type="sect1">
|
||||
<section id="workflow-pipes-summary" data-type="sect1">
|
||||
<h1>
|
||||
Summary</h1>
|
||||
<p>In this chapter, you’ve learned more about the pipe: why we recommend it and some of the history that lead to <code>|></code>. The pipe is important because you’ll 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>
|
||||
|
||||
Reference in New Issue
Block a user