You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I found the below example work well but no related description in current official document.
.names A glue specification that describes how to name the output columns. This can use {.col} to stand for the selected column name, and {.fn} to stand for the name of the function being applied. The default (NULL) is equivalent to "{.col}" for the single function case and "{.col}_{.fn}" for the case where a list is used for .fns.
I just want to confirm whether this way is right or accepted, especilly when the new variable names can not simply be computed by {.col} or {.fn}
library(dplyr, warn.conflicts=FALSE)
df<-tibble::tibble(a=1, b=2, c=3)
cols<- c("a", "b", "c")
new_cols<- c("x", "y", "z")
df %>%
mutate(across(
.cols= all_of(cols),
.fns=~.x+10,
.names="{new_cols}"
))
#> # A tibble: 1 × 6#> a b c x y z#> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>#> 1 1 2 3 11 12 13
Thank very much for your reply.
The text was updated successfully, but these errors were encountered:
Since the doc says it's a glue specification I believe the behavior is accepted (though happy to see it confirmed), but maybe the intent might be made clearer by either of those 2, though these might also slightly bite into the undocumented territory.
The former uses the fact that across returns a data frame, so should be stable, unless across() is changed to only be recognised at the top level in dplyr verbs (it's not very clear from the doc if only top level is expected).
The latter is not 100% documented either but pretty close through #6655
Dear developer,
I found the below example work well but no related description in current official document.
I just want to confirm whether this way is right or accepted, especilly when the new variable names can not simply be computed by
{.col}
or{.fn}
Thank very much for your reply.
The text was updated successfully, but these errors were encountered: