<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/dplyr-0-7-0/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://blog.rstudio.org/2017/06/13/dplyr-0-7-0/"> RStudio Blog</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>I’m pleased to announce that dplyr 0.7.0 is now on CRAN! (This was dplyr 0.6.0 previously; more on that below.) dplyr provides a “grammar” of data transformation, making it easy and elegant to solve the most common data manipulation challenges. dplyr supports multiple backends: as well as in-memory data frames, you can also use it with remote SQL databases. If you haven’t heard of dplyr before, the best place to start is the <a rel="nofollow" href="http://r4ds.had.co.nz/transform.html" target="_blank">Data transformation</a> chapter in <a rel="nofollow" href="http://r4ds.had.co.nz/" target="_blank">R for Data Science</a>.</p>
<p>You can install the latest version of dplyr with:</p>
<pre><code><span>install.packages</span><span>(</span><span>&quot;dplyr&quot;</span><span>)</span></code></pre>
<div>
<h2>Features</h2>
<p>dplyr 0.7.0 is a major release including over 100 improvements and bug fixes, as described in the <a rel="nofollow" href="https://github.com/tidyverse/dplyr/releases/tag/v0.7.0" target="_blank">release notes</a>. In this blog post, I want to discuss one big change and a handful of smaller updates. This version of dplyr also saw a major revamp of database connections. That’s a big topic, so it’ll get its own blog post next week.</p>
<div>
<h3>Tidy evaluation</h3>
<p>The biggest change is a new system for programming with dplyr, called <strong>tidy evaluation</strong>, or tidy eval for short. Tidy eval is a system for capturing expressions and later evaluating them in the correct context. It is is important because it allows you to interpolate values in contexts where dplyr usually works with expressions:</p>
<pre><code><span>my_var</span> <span>&lt;-</span> <span>quo</span><span>(</span><span>homeworld</span><span>)</span>

<span>starwars</span> <span>%>%</span>
  <span>group_by</span><span>(</span><span>!</span><span>!</span><span>my_var</span><span>)</span> <span>%>%</span>
  <span>summarise_at</span><span>(</span><span>vars</span><span>(</span><span>height</span><span>:</span><span>mass</span><span>)</span>, <span>mean</span>, <span>na.rm</span> <span>=</span> <span>TRUE</span><span>)</span>
#> # A tibble: 49 x 3
#>         homeworld   height  mass
#>                  
#>  1       Alderaan 176.3333  64.0
#>  2    Aleen Minor  79.0000  15.0
#>  3         Bespin 175.0000  79.0
#>  4     Bestine IV 180.0000 110.0
#>  5 Cato Neimoidia 191.0000  90.0
#>  6          Cerea 198.0000  82.0
#>  7       Champala 196.0000   NaN
#>  8      Chandrila 150.0000   NaN
#>  9   Concord Dawn 183.0000  79.0
#> 10       Corellia 175.0000  78.5
#> # ... with 39 more rows</code></pre>
<p>This makes it possible to write your functions that work like dplyr functions, reducing the amount of copy-and-paste in your code:</p>
<pre><code><span>starwars_mean</span> <span>&lt;-</span> <span>function</span><span>(</span><span>my_var</span><span>)</span> <span>{</span>
  <span>my_var</span> <span>&lt;-</span> <span>enquo</span><span>(</span><span>my_var</span><span>)</span>
  
  <span>starwars</span> <span>%>%</span>
    <span>group_by</span><span>(</span><span>!</span><span>!</span><span>my_var</span><span>)</span> <span>%>%</span>
    <span>summarise_at</span><span>(</span><span>vars</span><span>(</span><span>height</span><span>:</span><span>mass</span><span>)</span>, <span>mean</span>, <span>na.rm</span> <span>=</span> <span>TRUE</span><span>)</span>
<span>}</span>
<span>starwars_mean</span><span>(</span><span>homeworld</span><span>)</span></code></pre>
<p>You can also use the new <code>.data</code> pronoun to refer to variables with strings:</p>
<pre><code><span>my_var</span> <span>&lt;-</span> <span>&quot;homeworld&quot;</span>

<span>starwars</span> <span>%>%</span>
  <span>group_by</span><span>(</span><span>.data</span><span>[</span><span>[</span><span>my_var</span><span>]</span><span>]</span><span>)</span> <span>%>%</span>
  <span>summarise_at</span><span>(</span><span>vars</span><span>(</span><span>height</span><span>:</span><span>mass</span><span>)</span>, <span>mean</span>, <span>na.rm</span> <span>=</span> <span>TRUE</span><span>)</span></code></pre>
<p>This is useful when you’re writing packages that use dplyr code because it avoids an annoying note from <code>R CMD check</code>.</p>
<p>To learn more about how tidy eval helps solve data analysis challenge, please read the new <a rel="nofollow" href="http://dplyr.tidyverse.org/articles/programming.html" target="_blank">programming with dplyr</a> vignette. Tidy evaluation is implemented in the <a rel="nofollow" href="http://rlang.tidyverse.org/" target="_blank">rlang</a> package, which also provides a vignette on the <a rel="nofollow" href="http://rlang.tidyverse.org/articles/tidy-evaluation.html" target="_blank">theoretical underpinnings</a>. Tidy eval is a rich system and takes a while to get your head around it, but we are confident that learning tidy eval will pay off, especially as it roles out to other packages in the tidyverse (tidyr and ggplot2 are next on the todo list).</p>
<p>The introduction of tidy evaluation means that the standard evaluation (underscored) version of each main verb (<code>filter_()</code>, <code>select_()</code> etc) is no longer needed, and so these functions have been deprecated (but remain around for backward compatibility).</p>
</div>
<div>
<h3>Character encoding</h3>
<p>We have done a lot of work to ensure that dplyr works with encodings other than Latin1 on Windows. This is most likely to affect you if you work with data that contains Chinese, Japanese, or Korean (CJK) characters. dplyr should now just work with such data. Please let us know if you have problems!</p>
</div>
<div>
<h3>New datasets</h3>
<p>dplyr has some new datasets that will help write more interesting examples:</p>
<ul>
<li><code>starwars</code>, shown above, contains information about characters from the Star Wars movies, sourced from the <a rel="nofollow" href="https://swapi.co/" target="_blank">Star Wars API</a>. It contains a number of list-columns.
<pre><code><span>starwars</span>
#> # A tibble: 87 x 13
#>                  name height  mass    hair_color  skin_color eye_color
#>                                         
#>  1     Luke Skywalker    172    77         blond        fair      blue
#>  2              C-3PO    167    75                  gold    yellow
#>  3              R2-D2     96    32           white, blue       red
#>  4        Darth Vader    202   136          none       white    yellow
#>  5        Leia Organa    150    49         brown       light     brown
#>  6          Owen Lars    178   120   brown, grey       light      blue
#>  7 Beru Whitesun lars    165    75         brown       light      blue
#>  8              R5-D4     97    32            white, red       red
#>  9  Biggs Darklighter    183    84         black       light     brown
#> 10     Obi-Wan Kenobi    182    77 auburn, white        fair blue-gray
#> # ... with 77 more rows, and 7 more variables: birth_year ,
#> #   gender , homeworld , species , films ,
#> #   vehicles , starships </code></pre>
</li>
<li><code>storms</code> has the trajectories of ~200 tropical storms. It contains a strong grouping structure.
<pre><code><span>storms</span>
#> # A tibble: 10,010 x 13
#>     name  year month   day  hour   lat  long              status category
#>                             
#>  1   Amy  1975     6    27     0  27.5 -79.0 tropical depression       -1
#>  2   Amy  1975     6    27     6  28.5 -79.0 tropical depression       -1
#>  3   Amy  1975     6    27    12  29.5 -79.0 tropical depression       -1
#>  4   Amy  1975     6    27    18  30.5 -79.0 tropical depression       -1
#>  5   Amy  1975     6    28     0  31.5 -78.8 tropical depression       -1
#>  6   Amy  1975     6    28     6  32.4 -78.7 tropical depression       -1
#>  7   Amy  1975     6    28    12  33.3 -78.0 tropical depression       -1
#>  8   Amy  1975     6    28    18  34.0 -77.0 tropical depression       -1
#>  9   Amy  1975     6    29     0  34.4 -75.8      tropical storm        0
#> 10   Amy  1975     6    29     6  34.0 -74.8      tropical storm        0
#> # ... with 10,000 more rows, and 4 more variables: wind ,
#> #   pressure , ts_diameter , hu_diameter </code></pre>
</li>
<li><code>band_members</code>, <code>band_instruments</code> and <code>band_instruments2</code> has a tiny amount of data about bands. It’s designed to be very simple so you can illustrate how joins work without getting distracted by the details of the data.
<pre><code><span>band_members</span>
#> # A tibble: 3 x 2
#>    name    band
#>      
#> 1  Mick  Stones
#> 2  John Beatles
#> 3  Paul Beatles
<span>band_instruments</span>
#> # A tibble: 3 x 2
#>    name  plays
#>     
#> 1  John guitar
#> 2  Paul   bass
#> 3 Keith guitar</code></pre>
</li>
</ul>
</div>
<div>
<h3>New and improved verbs</h3>
<ul>
<li>The <code>pull()</code> generic allows you to extract a single column either by name or position. It’s similar to <code>select()</code> but returns a vector, rather than a smaller tibble.
<pre><code><span>mtcars</span> <span>%>%</span> <span>pull</span><span>(</span><span>-</span><span>1</span><span>)</span> <span>%>%</span> <span>str</span><span>(</span><span>)</span>
#>  num [1:32] 4 4 1 1 2 1 4 2 2 4 ...
<span>mtcars</span> <span>%>%</span> <span>pull</span><span>(</span><span>cyl</span><span>)</span> <span>%>%</span> <span>str</span><span>(</span><span>)</span>
#>  num [1:32] 6 6 4 6 8 6 8 4 4 6 ...</code></pre>
<p>Thanks to <a rel="nofollow" href="https://github.com/paulponcet" target="_blank">Paul Poncet</a> for the idea!
<li><code>arrange()</code> for grouped data frames gains a <code>.by_group</code> argument so you can choose to sort by groups if you want to (defaults to <code>FALSE</code>).</li>
<li>All single table verbs now have scoped variantssuffixed with <code>_if()</code>, <code>_at()</code> and <code>_all()</code>. Use these if you want to do something to every variable (<code>_all</code>), variables selected by their names (<code>_at</code>), or variables that satisfy some predicate (<code>_if</code>).
<pre><code><span>iris</span> <span>%>%</span> <span>summarise_if</span><span>(</span><span>is.numeric</span>, <span>mean</span><span>)</span>
<span>starwars</span> <span>%>%</span> <span>select_if</span><span>(</span><span>Negate</span><span>(</span><span>is.list</span><span>)</span><span>)</span>
<span>storms</span> <span>%>%</span> <span>group_by_at</span><span>(</span><span>vars</span><span>(</span><span>month</span><span>:</span><span>hour</span><span>)</span><span>)</span></code></pre>
</li>


<div>
<h3>Other important changes</h3>
<ul>
<li>Local join functions can now control how missing values are matched. The default value is <code>na_matches = &quot;na&quot;</code>, which treats two missing values as equal. To prevent missing values from matching, use <code>na_matches = &quot;never&quot;</code>.</li>
</ul>
<p>You can change the default behaviour by calling <code>pkgconfig::set_config(&quot;dplyr::na_matches&quot;, &quot;never&quot;)</code>.</p>
<ul>
<li><code>bind_rows()</code> and <code>combine()</code> are more strict when coercing. Logical values are no longer coerced to integer and numeric. Date, POSIXct and other integer or double-based classes are no longer coerced to integer or double to avoid dropping important metadata. We plan to continue improving this interface in the future.</li>
</ul>
</div>

<div>
<h2>Breaking changes</h2>
<p>From time-to-time I discover that I made a mistake in an older version of dplyr and developed what is now a clearly suboptimal API. If the problem isn’t too big, I try to just leave it – the cost of making small improvements is not worth it when compared to to the cost of breaking existing code. However, there are bigger improvements where I believe the short-term pain of breaking code is worth the long-term payoff of a better API.</p>
<p>Regardless, it’s still frustrating when an update to dplyr breaks your code. To minimise this pain, I plan to do two things going forward:</p>
<ul>
<li>Adopt an odd-even release cycle so that API breaking changes only occur in odd numbered releases. Even numbered releases will only contain bug fixes and new features. This is why I’ve skipped dplyr 0.6.0 and gone directly to dplyr 0.7.0.</li>
<li>Invest time in developing better tools isolating packages across projects so that you can choose when to upgrade a package on a project-by-project basis, and if something goes wrong, easily roll back to a version that worked. Look for news about this later in the year.</li>
</ul>
</div>
<div>
<h2>Contributors</h2>
<p>dplyr is truly a community effort. Apart from the dplyr team (myself, <a rel="nofollow" href="https://github.com/krlmlr" target="_blank">Kirill Müller</a>, and <a rel="nofollow" href="https://github.com/lionel-" target="_blank">Lionel Henry</a>), this release wouldn’t have been possible without patches from <a rel="nofollow" href="https://github.com/cderv" target="_blank">Christophe Dervieux</a>, <a rel="nofollow" href="https://github.com/daattali" target="_blank">Dean Attali</a>, <a rel="nofollow" href="https://github.com/ianmcook" target="_blank">Ian Cook</a>, <a rel="nofollow" href="https://github.com/ijlyttle" target="_blank">Ian Lyttle</a>, <a rel="nofollow" href="https://github.com/JakeRuss" target="_blank">Jake Russ</a>, <a rel="nofollow" href="https://github.com/jayhesselberth" target="_blank">Jay Hesselberth</a>, <a rel="nofollow" href="https://github.com/jennybc" target="_blank">Jennifer (Jenny) Bryan</a>, <a rel="nofollow" href="https://github.com/lindbrook" target="_blank">@lindbrook</a>, <a rel="nofollow" href="https://github.com/maurolepore" target="_blank">Mauro Lepore</a>, <a rel="nofollow" href="https://github.com/npjc" target="_blank">Nicolas Coutin</a>, <a rel="nofollow" href="https://github.com/strengejacke" target="_blank">Daniel</a>, <a rel="nofollow" href="https://github.com/tonyfischetti" target="_blank">Tony Fischetti</a>, <a rel="nofollow" href="https://github.com/yutannihilation" target="_blank">Hiroaki Yutani</a> and <a rel="nofollow" href="https://github.com/zeehio" target="_blank">Sergio Oller</a>. Thank you all for your contributions!</p>
</div>
<p> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/rstudioblog.wordpress.com/4658/" target="_blank"><img border="0" alt="" src="http://feeds.wordpress.com/1.0/comments/rstudioblog.wordpress.com/4658/"></a> <img border="0" alt="" src="https://i1.wp.com/pixel.wp.com/b.gif?resize=1%2C1&ssl=1" data-recalc-dims="1"></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="https://blog.rstudio.org/2017/06/13/dplyr-0-7-0/"> RStudio 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/6SVcZ_utmjQ" height="1"></a></div></ul></div></div>