How does dplyr's select helper function everything() differ from copying?

dataframe, dplyr, r

Solution

Looking for references to `everything` in `?select`, they have an example use for reordering columns:

# Reorder variables: keep the variable "Species" in the front
select(iris, Species, everything())

In this case the `Species` column is moved to the first column, all columns are kept, and no columns are duplicated.

Select helpers are used for more than just the `select` function - for example, in `dplyr` version 1.0 and greater, you may want to use it in `across()` to mutate or summarize all columns.

Since this question was asked, the select helpers have been broken out into their own package, `tidyselect`. The `tidyselect` page on CRAN has a lengthy list of reverse imports - it's likely that many of the packages importing `tidyselect` have cases where `everything()` is useful.

Problem

What is the use case for ``` select(iris, everything()) ``` as opposed to e.g. just copying the data.frame?

Original source

Related problems