<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/quoting-concatenate/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://www.win-vector.com/blog/2018/12/quoting-concatenate/"> R – Win-Vector Blog</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>In our <a rel="nofollow" href="http://www.win-vector.com/blog/2018/12/reusable-pipelines-in-r/" target="_blank">last note</a> we used <a rel="nofollow" href="https://winvector.github.io/wrapr/reference/qe.html" target="_blank"><code>wrapr::qe()</code></a> to help quote expressions. In this note we will discuss quoting and code-capturing interfaces (interfaces that capture user source code) a bit more.</p>
<p><span></span></p>
<p>
<p>My position on code-capturing interfaces (or non-standard-evaluation/NSE) is: <em>if</em> poorly handled, they can be a large interface price/risk to pay for the minor convenience of eliding a few quotation marks.</p>
<p>Computation is meant to be over values. In fact one can think of computation as transforming code plus initial values to resulting values.</p>
<p>Our <a rel="nofollow" href="https://github.com/WinVector/wrapr" target="_blank"><code>wrapr</code></a> <a rel="nofollow" href="https://www.r-project.org/" target="_blank"><code>R</code></a> package has the sensible design principle: NSE can be convenient, but we are going to isolate it to a few methods. Users then pass the objects that those methods create as <em>values</em> to other methods.</p>
<p>The primary place code capturing shows up in our <code>wrapr</code> <code>R</code> package is in the <a rel="nofollow" href="https://winvector.github.io/wrapr/reference/qc.html" target="_blank"><code>qc()</code></a> and <a rel="nofollow" href="https://winvector.github.io/wrapr/reference/qchar_frame.html" target="_blank"><code>qchar_frame()</code></a> methods.</p>
<p><code>qc()</code> is “quoting concatenate” it is much like <code>c()</code>, but it quotes its arguments.</p>
<p>It lets you replace this:</p>
<pre>
   dplyr::select(iris, Petal.Width, Petal.Length)
</pre>
<p>with this:</p>
<pre>
   library(&quot;wrapr&quot;)
   iris[, qc(Petal.Width, Petal.Length)]
</pre>
<p>We skipped the quotes, and the NSE stuff is safely isolated from the rest of the system.</p>
<p>A nice addition is: the latest version of <code>wrapr</code> incorporates <code>base::bquote()</code> based quasiquotation.</p>
<p>Quasiquotation was introduced into R by Thomas Lumley in 2003, and allows users to signal they want to turn off quotation for portions of their code. The user indicates they do not wish a portion of their code to be quoted (but instead want it evaluated for its value) by surrounding that portion with the function-notation “<code>.()</code>“.</p>
<p>An example of this is given here.</p>
<pre>
  library(&quot;wrapr&quot;)

  OTHER_SYMBOL &lt;- &quot;Petal.Length&quot;

  qc(Petal.Width, OTHER_SYMBOL)
  # [1] &quot;Petal.Width&quot;  &quot;OTHER_SYMBOL&quot;

  qc(Petal.Width, .(OTHER_SYMBOL))
  # [1] &quot;Petal.Width&quot;  &quot;Petal.Length&quot;
</pre>
<p><code>base::bquote()</code> was a significant contribution to <code>R</code> that deserves a lot more attention, respect, credit, priority, and deference than it appears to have received recently. I would suggest package authors look into incorporating <code>base::bquote()</code> into own their work, before moving on to newer extension packages. We are not saying <em>here</em> “use the <code>wrapr</code> package” (though we do say that often, as it makes our own work much easier and very much want to share the <code>wrapr</code> package). We are saying: “give <code>base::bquote()</code> in your own packages.” The “<code>.()</code>“-notation is already standard to <code>R</code>, and a good standard notation for users to expect from <code>R</code> packages.</p>
<p>For our part, we have found incorporating <code>base::bquote()</code> into our own work to be easy and rewarding.</p>
	<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="http://www.win-vector.com/blog/2018/12/quoting-concatenate/"> R – Win-Vector Blog</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a rel="nofollow" href="https://www.r-project.org/" title="The R Project for Statistical Computing">R</a> news and <a rel="nofollow" href="https://www.r-bloggers.com/search/tutorial" title="R tutorials">tutorials</a> on topics such as: <a rel="nofollow" href="https://www.r-bloggers.com/search/data%20science" title="Data science">Data science</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data" title="Big Data">Big Data, <a rel="nofollow" href="https://www.r-users.com/" title="R jobs">R jobs</a>, visualization (<a rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2" title="ggplot and ggplot2 tutorials">ggplot2</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/boxplot" title="Boxplots using lattice and ggplot2 tutorials">Boxplots</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/map" title="Maps and gis">maps</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/animation" title="Animation in R">animation</a>), programming (<a rel="nofollow" href="https://www.r-bloggers.com/search/RStudio" title="RStudio IDE for R">RStudio</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/sweave" title="Sweave and literate programming">Sweave</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX" title="LaTeX in R">LaTeX</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/SQL" title="SQL and databases">SQL</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/eclipse" title="Eclipse IDE for R">Eclipse</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/git" title="git and github, Version Control System">git</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/hadoop" title="Large data in R using Hadoop">hadoop</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping" title="Web Scraping of google, facebook, yahoo, twitter and more using R">Web Scraping</a>) statistics (<a rel="nofollow" href="https://www.r-bloggers.com/search/regression" title="Regressions and ANOVA analysis tutorials">regression</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/PCA" title="principal component analysis tutorial">PCA</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/time+series" title="Time series">time series</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/trading" title="finance trading">trading</a>) and more...
<img width="1" alt="" src="http://feeds.feedburner.com/~r/RBloggers/~4/2OPEVVEYPV0" height="1"></a></div>