Skip to content

Commit

Permalink
Add example of named vector for all_of() and any_of() (#356)
Browse files Browse the repository at this point in the history
  • Loading branch information
laplasi authored Oct 22, 2024
1 parent bcf8385 commit 3ad00d7
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ Config/Needs/website: tidyverse/tidytemplate
Config/testthat/edition: 3
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.0.9000
RoxygenNote: 7.3.2
10 changes: 9 additions & 1 deletion R/helpers-vector.R
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
#' iris %>% pivot_longer(all_of(vars))
#' ```
#'
#' If any of the variable is missing from the data frame, that's an error:
#' If any of these variables are missing from the data frame, that's an error:
#'
#' ```{r, error = TRUE}
#' starwars %>% select(all_of(vars))
Expand All @@ -71,6 +71,14 @@
#' iris %>% select(-any_of(vars)) %>% select(-any_of(vars))
#' ```
#'
#' Supply named vectors to `all_of()` and `any_of()` to select and rename
#' columns at the same time:
#'
#' ```{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
19 changes: 17 additions & 2 deletions man/all_of.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3ad00d7

Please sign in to comment.