Skip to content

Commit

Permalink
Add example of named vector x for all_of() and any_of()
Browse files Browse the repository at this point in the history
`all_of()` and `any_of()` have special behaviour when `x` is a named vector. See r-lib#333. 

(First commit to a project)
  • Loading branch information
laplasi authored Aug 30, 2024
1 parent fd22cc1 commit 86f9cfd
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions R/helpers-vector.R
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,15 @@
#' iris %>% select(-any_of(vars)) %>% select(-any_of(vars))
#' ```
#'
#' When the vector `x` is named, `all_of()` and `any_of()` will
#' select columns using the values of x, but then return those columns
#' renamed with the corresponding names from names(x).
#'
#' ```{r, comment = "#>", collapse = TRUE}
#' colors <- c(color_of_hair = "hair_color", color_of_eyes = "eye_color")
#' starwars %>% select(all_of(colors))
#' ```
#'
#' @seealso `r rd_helpers_seealso()`
#' @export
all_of <- function(x) {
Expand Down

0 comments on commit 86f9cfd

Please sign in to comment.