<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/an-introduction-to-seplyr/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://blog.revolutionanalytics.com/2017/12/introduction-to-seplyr.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 John Mount, Win-Vector LLC</em></p>
<p><a rel="nofollow" href="https://winvector.github.io/seplyr/" target="_blank"><code>seplyr</code></a> is an <a rel="nofollow" href="https://www.r-project.org/" target="_blank"><code>R</code></a> package<br>
that supplies improved standard evaluation interfaces for many common data wrangling tasks.</p>
<p>The core of <code>seplyr</code> is a<br>
re-skinning of <a rel="nofollow" href="https://cran.r-project.org/package=dplyr" target="_blank"><code>dplyr</code></a>'s<br>
functionality to <code>seplyr</code> conventions (similar to how <a rel="nofollow" href="https://cran.r-project.org/package=stringr" target="_blank"><code>stringr</code></a><br>
re-skins the implementing package <a rel="nofollow" href="https://cran.r-project.org/package=stringi" target="_blank"><code>stringi</code></a>).</p>
<h2>Standard Evaluation and Non-Standard Evaluation</h2>
<p>&quot;Standard evaluation&quot; is the name we are using for the value oriented calling convention found in many programming languages. The idea is: functions are only allowed to look at the values of their arguments and not how those values arise (i.e., they can not look at source code or variable names). This evaluation principle allows one to transform, optimize, and reason about code. </p>
<p>It is what lets us say the following two snippets of code are equivalent.</p>
<ul>
<li><code>x &lt;- 4; sqrt(x)</code></li>
<li><code>x &lt;- 4; sqrt(4)</code></li>
</ul>
<p>The mantra is: </p>
<blockquote>
<p>&quot;variables can be replaced with their values.&quot;</p>
</blockquote>
<p>Which is called <a rel="nofollow" href="https://en.wikipedia.org/wiki/Referential_transparency" target="_blank">referential transparency</a>.</p>
<p><a rel="nofollow" href="http://adv-r.had.co.nz/Computing-on-the-language.html" target="_blank">&quot;Non-standard evaluation&quot;</a> is the name used for code that more aggressively inspects its environment. It is often used for harmless tasks such as conveniently setting axis labels on plots. For example, notice the following two plots have different y-axis labels (despite plotting identical values).</p>
<pre><code>plot(x = 1:3)
</code></pre>
<p><a rel="nofollow" href="http://revolution-computing.typepad.com/.a/6a010534b1db25970b01bb09df8498970d-pi" target="_blank"><img border="0" src="http://revolution-computing.typepad.com/.a/6a010534b1db25970b01bb09df8498970d-800wi" alt="Plot1" width="300" title="Plot1"></a></p>
<pre><code>plot(x = c(1,2,3))
</code></pre>
<p><a rel="nofollow" href="http://revolution-computing.typepad.com/.a/6a010534b1db25970b01b8d2c6cc2a970c-pi" target="_blank"><img border="0" src="http://revolution-computing.typepad.com/.a/6a010534b1db25970b01b8d2c6cc2a970c-800wi" alt="Plot2" width="300" title="Plot2"></a></p>
<h2><code>dplyr</code> and <code>seplyr</code></h2>
<p>The <code>dplyr</code> authors appear to <em>strongly</em> prefer a non-standard evaluation interface. Many in the <code>dplyr</code> community have come to <em>think</em> a package such as <code>dplyr</code> requires a non-standard interface. <code>seplyr</code> started as an experiment to show this is not actually the case.</p>
<p>Syntactically the packages are deliberately similar.</p>
<p>We can take a <code>dplyr</code> pipeline:</p>
<pre><code>suppressPackageStartupMessages(library(&quot;dplyr&quot;))

starwars %>%
  select(name, height, mass) %>%
  arrange(desc(height)) %>%
  head()

## # A tibble: 6 x 3
##           name height  mass
##          </code></pre></div>