EVOLUTION-MANAGER
Edit File: tidyr_tidy_select.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: Argument type: tidy-select</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 tidyr_tidy_select {tidyr}"><tr><td>tidyr_tidy_select {tidyr}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Argument type: tidy-select</h2> <h3>Description</h3> <p>This page the describes the <code style="white-space: pre;"><tidy-select></code> argument modifier which indicates the argument uses <strong>tidy selection</strong> (a special type of tidy evaluation). Tidy selection provides a concise DSL for selecting variables based on their names. </p> <h3>Overview of selection features</h3> <p>Tidyverse selections implement a dialect of R where operators make it easy to select variables: </p> <ul> <li> <p><code>:</code> for selecting a range of consecutive variables. </p> </li> <li> <p><code>!</code> for taking the complement of a set of variables. </p> </li> <li> <p><code>&</code> and <code>|</code> for selecting the intersection or the union of two sets of variables. </p> </li> <li> <p><code>c()</code> for combining selections. </p> </li></ul> <p>In addition, you can use <strong>selection helpers</strong>. Some helpers select specific columns: </p> <ul> <li> <p><code><a href="../../tidyselect/html/everything.html">everything()</a></code>: Matches all variables. </p> </li> <li> <p><code><a href="../../tidyselect/html/everything.html">last_col()</a></code>: Select last variable, possibly with an offset. </p> </li></ul> <p>These helpers select variables by matching patterns in their names: </p> <ul> <li> <p><code><a href="../../tidyselect/html/starts_with.html">starts_with()</a></code>: Starts with a prefix. </p> </li> <li> <p><code><a href="../../tidyselect/html/starts_with.html">ends_with()</a></code>: Ends with a suffix. </p> </li> <li> <p><code><a href="../../tidyselect/html/starts_with.html">contains()</a></code>: Contains a literal string. </p> </li> <li> <p><code><a href="../../tidyselect/html/starts_with.html">matches()</a></code>: Matches a regular expression. </p> </li> <li> <p><code><a href="../../tidyselect/html/starts_with.html">num_range()</a></code>: Matches a numerical range like x01, x02, x03. </p> </li></ul> <p>These helpers select variables from a character vector: </p> <ul> <li> <p><code><a href="../../tidyselect/html/all_of.html">all_of()</a></code>: Matches variable names in a character vector. All names must be present, otherwise an out-of-bounds error is thrown. </p> </li> <li> <p><code><a href="../../tidyselect/html/all_of.html">any_of()</a></code>: Same as <code>all_of()</code>, except that no error is thrown for names that don't exist. </p> </li></ul> <p>This helper selects variables with a function: </p> <ul> <li> <p><code><a href="../../tidyselect/html/where.html">where()</a></code>: Applies a function to all variables and selects those for which the function returns <code>TRUE</code>. </p> </li></ul> <h3>Indirection</h3> <p>There are two main cases: </p> <ul> <li><p> If you have a character vector of column names, use <code>all_of()</code> or <code>any_of()</code>, depending on whether or not you want unknown variable names to cause an error, e.g <code>unnest(df, all_of(vars))</code>, <code>unnest(df, !any_of(vars))</code>. </p> </li> <li><p> If you want the user to supply a tidyselect specification in a function argument, you need to tunnel the selection through the function argument. This is done by embracing the function argument <code>{{ }}</code>, e.g <code>unnest(df, {{ vars }})</code>. </p> </li></ul> <p>Learn more in <code>vignette("programming.Rmd")</code>. </p> <hr /><div style="text-align: center;">[Package <em>tidyr</em> version 1.1.2 <a href="00Index.html">Index</a>]</div> </body></html>