<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/non-standard-evaluation-how-tidy-eval-builds-on-base-r/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://edwinth.github.io/blog/nse/"> That’s so Random</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>As with many aspects of the tidyverse, its non-standard evaluation (NSE) implementation is not something entirely new, but built on top of base R. What makes this one so challenging to get your mind around, is that the <a rel="nofollow" href="http://maraaverick.rbind.io/2017/08/tidyeval-resource-roundup/" target="_blank">Honorable Doctor Sir Lord General</a> and friends brought concepts to the realm of the mortals that many of us had no, or only a vague, understanding of. Earlier, I gave an overview of <a rel="nofollow" href="https://edwinth.github.io/blog/dplyr-recipes/" target="_blank">the most common actions in tidy eval</a>. Although appreciated by many, it left me unsatisfied, because it made clear to me I did not really understand NSE. Neither in base R, nor in tidy eval. Therefore, I bit the bullet and really studied it for a few evenings. Starting with base R NSE, and later learning what tidy eval actually adds to it. I decided to share the things I learned in this, rather lengthy, blog. I think it captures the essentials in NSE, although it surely is incomplete and might be even erronous at places. Still, I hope you find it worthwhile and it will help you understand NSE better and apply it with more confidence.</p>
<p>My approach was listing a number of terms and study them one by one. Mainly consulting <a rel="nofollow" href="http://adv-r.hadley.nz/" target="_blank">Advanced R</a> and the <a rel="nofollow" target="_blank">R Language Definition</a>. For tidy eval I leaned heavily on the <a rel="nofollow" href="https://cran.r-project.org/web/packages/dplyr/vignettes/programming.html" target="_blank">Programming with dplyr vignette</a> and the function documentations. This is also how this blog post is built. We are hopping from term to term, to we see how they relate. You will find references to the sources in the text, in case you want to read more about a topic.</p>
<h1>Base R, non-standard evaluation</h1>
<h2><code>expression</code></h2>
<p>In standard evaluation R is like a child that receives candy from his grandmother and puts it in his mouth immediately. Every input is evaluated right away. This can be collecting the value of an object or letting a function do a calculation. An <strong>expression</strong> is some R code that is ready to be evaluated, but is not evaluated yet. Rather it is captured and saved for later. Think of it as the child’s father telling he can’t have the candy until they get home. The base R way of creating an expression is by using <code>parse(text = &quot;</code>