Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

dplyr_tidy_select

Argument type: tidy-select


Description

This page the describes the <tidy-select> argument modifier which indicates the argument supports tidy selections. Tidy selection provides a concise dialect of R for selecting variables based on their names or properties.

Tidy selection is a variant of tidy evaluation. This means that inside functions, tidy-select arguments require special attention, as described in the Indirection section. If you've never heard of tidy evaluation before, start with vignette("programming").

Overview of selection features

Tidyverse selections implement a dialect of R where operators make it easy to select variables:

  • : for selecting a range of consecutive variables.

  • ! for taking the complement of a set of variables.

  • & and | for selecting the intersection or the union of two sets of variables.

  • c() for combining selections.

In addition, you can use selection helpers. Some helpers select specific columns:

These helpers select variables by matching patterns in their names:

These helpers select variables from a character vector:

  • all_of(): Matches variable names in a character vector. All names must be present, otherwise an out-of-bounds error is thrown.

  • any_of(): Same as all_of(), except that no error is thrown for names that don't exist.

This helper selects variables with a function:

  • where(): Applies a function to all variables and selects those for which the function returns TRUE.

Indirection

There are two main cases:

  • If you have a character vector of column names, use all_of() or any_of(), depending on whether or not you want unknown variable names to cause an error, e.g select(df, all_of(vars)), select(df, !any_of(vars)).

  • If you you want the user to supply a tidyselect specification in a function argument, embrace the function argument, e.g select(df, {{ vars }}).


dplyr

A Grammar of Data Manipulation

v1.0.6
MIT + file LICENSE
Authors
Hadley Wickham [aut, cre] (<https://orcid.org/0000-0003-4757-117X>), Romain François [aut] (<https://orcid.org/0000-0002-2444-4226>), Lionel Henry [aut], Kirill Müller [aut] (<https://orcid.org/0000-0002-1416-3412>), RStudio [cph, fnd]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.