EVOLUTION-MANAGER
Edit File: scoped.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>R: Operate on a selection of variables</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="R.css" /> </head><body> <table width="100%" summary="page for scoped {dplyr}"><tr><td>scoped {dplyr}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Operate on a selection of variables</h2> <h3>Description</h3> <a href='https://www.tidyverse.org/lifecycle/#superseded'><img src='figures/lifecycle-superseded.svg' alt='Superseded lifecycle'></a> <p>Scoped verbs (<code style="white-space: pre;">_if</code>, <code style="white-space: pre;">_at</code>, <code style="white-space: pre;">_all</code>) have been superseded by the use of <code><a href="across.html">across()</a></code> in an existing verb. See <code>vignette("colwise")</code> for details. </p> <p>The variants suffixed with <code style="white-space: pre;">_if</code>, <code style="white-space: pre;">_at</code> or <code style="white-space: pre;">_all</code> apply an expression (sometimes several) to all variables within a specified subset. This subset can contain all variables (<code style="white-space: pre;">_all</code> variants), a <code><a href="vars.html">vars()</a></code> selection (<code style="white-space: pre;">_at</code> variants), or variables selected with a predicate (<code style="white-space: pre;">_if</code> variants). </p> <p>The verbs with scoped variants are: </p> <ul> <li> <p><code><a href="mutate.html">mutate()</a></code>, <code><a href="mutate.html">transmute()</a></code> and <code><a href="summarise.html">summarise()</a></code>. See <code><a href="summarise_all.html">summarise_all()</a></code>. </p> </li> <li> <p><code><a href="filter.html">filter()</a></code>. See <code><a href="filter_all.html">filter_all()</a></code>. </p> </li> <li> <p><code><a href="group_by.html">group_by()</a></code>. See <code><a href="group_by_all.html">group_by_all()</a></code>. </p> </li> <li> <p><code><a href="rename.html">rename()</a></code> and <code><a href="select.html">select()</a></code>. See <code><a href="select_all.html">select_all()</a></code>. </p> </li> <li> <p><code><a href="arrange.html">arrange()</a></code>. See <code><a href="arrange_all.html">arrange_all()</a></code> </p> </li></ul> <p>There are three kinds of scoped variants. They differ in the scope of the variable selection on which operations are applied: </p> <ul> <li><p> Verbs suffixed with <code style="white-space: pre;">_all()</code> apply an operation on all variables. </p> </li> <li><p> Verbs suffixed with <code style="white-space: pre;">_at()</code> apply an operation on a subset of variables specified with the quoting function <code><a href="vars.html">vars()</a></code>. This quoting function accepts <code><a href="../../tidyselect/html/vars_select.html">tidyselect::vars_select()</a></code> helpers like <code><a href="reexports.html">starts_with()</a></code>. Instead of a <code><a href="vars.html">vars()</a></code> selection, you can also supply an <a href="../../rlang/html/is_integerish.html">integerish</a> vector of column positions or a character vector of column names. </p> </li> <li><p> Verbs suffixed with <code style="white-space: pre;">_if()</code> apply an operation on the subset of variables for which a predicate function returns <code>TRUE</code>. Instead of a predicate function, you can also supply a logical vector. </p> </li></ul> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>.tbl</code></td> <td> <p>A <code>tbl</code> object.</p> </td></tr> <tr valign="top"><td><code>.funs</code></td> <td> <p>A function <code>fun</code>, a quosure style lambda <code>~ fun(.)</code> or a list of either form.</p> </td></tr> <tr valign="top"><td><code>.vars</code></td> <td> <p>A list of columns generated by <code><a href="vars.html">vars()</a></code>, a character vector of column names, a numeric vector of column positions, or <code>NULL</code>.</p> </td></tr> <tr valign="top"><td><code>.predicate</code></td> <td> <p>A predicate function to be applied to the columns or a logical vector. The variables for which <code>.predicate</code> is or returns <code>TRUE</code> are selected. This argument is passed to <code><a href="../../rlang/html/as_function.html">rlang::as_function()</a></code> and thus supports quosure-style lambda functions and strings representing function names.</p> </td></tr> <tr valign="top"><td><code>...</code></td> <td> <p>Additional arguments for the function calls in <code>.funs</code>. These are evaluated only once, with <a href="../../rlang/html/dyn-dots.html">tidy dots</a> support.</p> </td></tr> </table> <h3>Grouping variables</h3> <p>Most of these operations also apply on the grouping variables when they are part of the selection. This includes: </p> <ul> <li> <p><code><a href="arrange_all.html">arrange_all()</a></code>, <code><a href="arrange_all.html">arrange_at()</a></code>, and <code><a href="arrange_all.html">arrange_if()</a></code> </p> </li> <li> <p><code><a href="distinct_all.html">distinct_all()</a></code>, <code><a href="distinct_all.html">distinct_at()</a></code>, and <code><a href="distinct_all.html">distinct_if()</a></code> </p> </li> <li> <p><code><a href="filter_all.html">filter_all()</a></code>, <code><a href="filter_all.html">filter_at()</a></code>, and <code><a href="filter_all.html">filter_if()</a></code> </p> </li> <li> <p><code><a href="group_by_all.html">group_by_all()</a></code>, <code><a href="group_by_all.html">group_by_at()</a></code>, and <code><a href="group_by_all.html">group_by_if()</a></code> </p> </li> <li> <p><code><a href="select_all.html">select_all()</a></code>, <code><a href="select_all.html">select_at()</a></code>, and <code><a href="select_all.html">select_if()</a></code> </p> </li></ul> <p>This is not the case for summarising and mutating variants where operations are <em>not</em> applied on grouping variables. The behaviour depends on whether the selection is <strong>implicit</strong> (<code>all</code> and <code>if</code> selections) or <strong>explicit</strong> (<code>at</code> selections). Grouping variables covered by explicit selections (with <code><a href="summarise_all.html">summarise_at()</a></code>, <code><a href="mutate_all.html">mutate_at()</a></code>, and <code><a href="mutate_all.html">transmute_at()</a></code>) are always an error. For implicit selections, the grouping variables are always ignored. In this case, the level of verbosity depends on the kind of operation: </p> <ul> <li><p> Summarising operations (<code><a href="summarise_all.html">summarise_all()</a></code> and <code><a href="summarise_all.html">summarise_if()</a></code>) ignore grouping variables silently because it is obvious that operations are not applied on grouping variables. </p> </li> <li><p> On the other hand it isn't as obvious in the case of mutating operations (<code><a href="mutate_all.html">mutate_all()</a></code>, <code><a href="mutate_all.html">mutate_if()</a></code>, <code><a href="mutate_all.html">transmute_all()</a></code>, and <code><a href="mutate_all.html">transmute_if()</a></code>). For this reason, they issue a message indicating which grouping variables are ignored. </p> </li></ul> <hr /><div style="text-align: center;">[Package <em>dplyr</em> version 1.0.2 <a href="00Index.html">Index</a>]</div> </body></html>