Skip to content

Commit

Permalink
Add named all_of() examples to across() docs (#6757)
Browse files Browse the repository at this point in the history
  • Loading branch information
DavisVaughan authored Feb 24, 2023
1 parent 3c0adff commit ae4efe1
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
17 changes: 17 additions & 0 deletions R/across.R
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,17 @@
#' iris %>%
#' mutate(across(where(is.double) & !c(Petal.Length, Petal.Width), round))
#'
#' # Using an external vector of names
#' cols <- c("Sepal.Length", "Petal.Width")
#' iris %>%
#' mutate(across(all_of(cols), round))
#'
#' # If the external vector is named, the output columns will be named according
#' # to those names
#' names(cols) <- tolower(cols)
#' iris %>%
#' mutate(across(all_of(cols), round))
#'
#' # A purrr-style formula
#' iris %>%
#' group_by(Species) %>%
Expand All @@ -126,6 +137,12 @@
#' group_by(Species) %>%
#' summarise(across(starts_with("Sepal"), list(mean = mean, sd = sd), .names = "{.col}.{.fn}"))
#'
#' # If a named external vector is used for column selection, .names will use
#' # those names when constructing the output names
#' iris %>%
#' group_by(Species) %>%
#' summarise(across(all_of(cols), mean, .names = "mean_{.col}"))
#'
#' # When the list is not named, .fn is replaced by the function's position
#' iris %>%
#' group_by(Species) %>%
Expand Down
17 changes: 17 additions & 0 deletions man/across.Rd

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

0 comments on commit ae4efe1

Please sign in to comment.