<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/in-defense-of-wraprlet/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://www.win-vector.com/blog/2017/06/in-defense-of-wraprlet/"> R – Win-Vector Blog</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>Saw this the other day:</p>
<p><a rel="nofollow" href="https://blog.rstudio.org/2017/04/13/dplyr-0-6-0-coming-soon/" target="_blank"><img border="0" src="https://i2.wp.com/www.win-vector.com/blog/wp-content/uploads/2017/06/wraprvstidyeval.png?w=660" alt="Wraprvstidyeval" title="wraprvstidyeval.png" data-recalc-dims="1"></a></p>
<p>In defense of <a rel="nofollow" href="https://cran.r-project.org/package=wrapr" target="_blank"><code>wrapr::let()</code></a> (originally part of <a rel="nofollow" href="https://cran.r-project.org/package=replyr" target="_blank"><code>replyr</code></a>, and still re-exported by that package) I would say:</p>
<ul>
<li><code>let()</code> was deliberately designed for a single <em>real-world use case</em>: working with data when you don’t know the column names when you are writing the code (i.e., the column names will come later in a variable). We can re-phrase that as: there is deliberately less to learn as <code>let()</code> is adapted to a need (instead of one having to adapt to <code>let()</code>).
</li>
<li>The <a rel="nofollow" href="https://cran.r-project.org/" target="_blank"><code>R</code></a> community already has months of experience confirming <code>let()</code> working reliably in production while interacting with a number of different packages.</li>
<li><code>let()</code> will continue to be a very specific, consistent, <a rel="nofollow" href="http://www.win-vector.com/blog/2017/05/why-to-use-wraprlet/" target="_blank">reliable</a>, and relevant tool even after <code>dpyr 0.6.*</code> is released, and the community gains experience with <code>rlang</code>/<code>tidyeval</code> in production.</li>
</ul>
<p>If <code>rlang</code>/<code>tidyeval</code> is your thing, by all means please use and teach it. But please continue to consider also using <code>wrapr::let()</code>. If you are trying to get something done quickly, or trying to share work with others: a “deeper theory” may not be the best choice.</p>
<p>An example follows.<span></span></p>
<p>
<p>
In “base <a rel="nofollow" href="https://www.r-project.org/" target="_blank">R</a>” one can write:
<pre>
d &lt;- data.frame(x = 1:3)
</pre>
<p>If we know the column name we wish to add to this data frame we write:</p>
<pre>
d$newColumn &lt;- 1
</pre>
<p>The above is “non-parameterized” evaluation in that the variable name is taken from the source code, and not from a variable carrying the information. This is great for ad-hoc analysis, but it would be hard to write functions, scripts and packages if this was the only way we had to manipulate columns.</p>
<p>This isn’t a problem as <code>R</code> supplies an additional parameterized notation as we show here. When we don’t know the name of the column (but expect it to be in a variable at run time) we write:</p>
<pre>
# code written very far away from us
variableHoldingColumnName &lt;- 'newColumn' 

# our code
d[[variableHoldingColumnName]] &lt;- 1
</pre>
<p>The purpose of <code>wrapr::let()</code> is to allow one to use the non-parameterized form <em>as if</em> it were parameterized. Obviously this is only useful if there is <em>not</em> a convenient parameterized alternative (which is the case for some packages). But for teaching purposes: how would <code>wrapr::let()</code> let us use the “<code>$</code>” <em>as if</em> it were parameterized (which we would have to do if <code>[[]]</code> and <code>[]</code> did not exist)?</p>
<p>With <code>wrapr::let()</code> we can re-write the “dollar-sign form” as:</p>
<pre>
wrapr::let(
   c(NEWCOL = variableHoldingColumnName),
   {
     d$NEWCOL &lt;- 1
   }
)
</pre>
<p>The name “<code>NEWCOL</code>” is a stand-in name that we write all our code in terms of. The expression “<code>c(NEWCOL = variableHoldingColumnName)</code>” is saying: “<code>NEWCOL</code> is to be interpreted as being whatever name is stored in the variable <code>variableHoldingColumnName</code>.” Notice we can’t tell from the code what value is in <code>variableHoldingColumnName</code>, as that won’t be known until execution time. The alias list or vector can be arbitrarily long and built wherever you like (it is just data). The expression block can be arbitrarily large and complex (so you need only pay the mapping notation cost once per function, not once per line of code).</p>
<p>And that is <code>wrapr::let()</code>.</p>
<p>If you don’t need parametric names you don’t need <code>wrapr::let()</code>. If you do need parametric names <code>wrapr::let()</code> is one of the most reliable and easiest to learn ways to get them. </p>
<p>A nice article from a user recording their experience trying different ways to parameterize their code (including <code>wrapr::let()</code>) can be found <a rel="nofollow" href="http://johnmackintosh.com/2017-06-01-UPDATED-let-there-be-progress/" target="_blank">here</a>.</p>
<p>If you wish to learn more we have a lot of resources available:</p>
<ul>
<li><b>A vignette:</b> <a rel="nofollow" href="https://cran.rstudio.com/web/packages/wrapr/vignettes/let.html" target="_blank"><code>vignette('let', package='wrapr')</code></a>.</li>
<li><b>The method help:</b> <code>help('let', package='wrapr')</code></li>
<li><b>Examples:</b> <a rel="nofollow" href="http://www.win-vector.com/blog/2016/12/using-replyrlet-to-parameterize-dplyr-expressions/" target="_blank">Using replyr::let to Parameterize dplyr Expressions</a>.</li>
<li><b>A video lecture:</b> <a rel="nofollow" href="http://www.win-vector.com/blog/2017/02/my-recent-barug-talk-parametric-programming-in-r-with-replyr/" target="_blank">My recent BARUG talk: Parametric Programming in R with replyr</a>.</li>
<li><b>Some notes:</b> <a rel="nofollow" href="https://github.com/WinVector/replyr/blob/master/vignettes/ParametricExample.Rmd" target="_blank">Parametric Programming in R</a>.</li>
<li><b>The package introduction:</b> The <a rel="nofollow" href="http://www.win-vector.com/blog/2017/03/wrapr-for-sweet-r-code/" target="_blank"><code>wrapr</code> introduction</a>.</li>
<li><b>Comparison to the soon to deprecated SE underbar/underscore methods:</b> <a rel="nofollow" href="http://www.win-vector.com/blog/2016/12/comparative-examples-using-replyrlet/" target="_blank">Comparative examples using replyr::let</a>.</li>
</ul>
<p>And many more examples on our blog.</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/2017/06/in-defense-of-wraprlet/"> 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/pOdqZ2neysY" height="1"></a></div>