Closed
Description
When using across()
within a grouped context, everything()
only selects all non-grouped variables. This is also documented in the code example of group_cols()
:
# Remove the grouping variables from mutate selections: gdf %>% mutate_at(vars(-group_cols()), `/`, 100) # -> No longer necessary with across() gdf %>% mutate(across(everything(), ~ . / 100))
And not surprisingly that is also what happens:
library(dplyr)
#>
#> Attache Paket: 'dplyr'
#> Die folgenden Objekte sind maskiert von 'package:stats':
#>
#> filter, lag
#> Die folgenden Objekte sind maskiert von 'package:base':
#>
#> intersect, setdiff, setequal, union
df <-
tibble(
id = c(1),
y = c("a"),
z = c("a")
)
df |>
summarize(
across(everything(), \(x) "test"),
.by = id
)
#> # A tibble: 1 × 3
#> id y z
#> <dbl> <chr> <chr>
#> 1 1 test test
Created on 2024-04-30 with reprex v2.1.0
When using the exact same verbs with the dbplyr backend, everthing()
really seems to select every column instead:
library(dplyr)
#>
#> Attache Paket: 'dplyr'
#> Die folgenden Objekte sind maskiert von 'package:stats':
#>
#> filter, lag
#> Die folgenden Objekte sind maskiert von 'package:base':
#>
#> intersect, setdiff, setequal, union
library(dbplyr)
#>
#> Attache Paket: 'dbplyr'
#> Die folgenden Objekte sind maskiert von 'package:dplyr':
#>
#> ident, sql
df <-
tibble(
id = c(1),
y = c("a"),
z = c("a")
)
tbl_lazy(df, dbplyr::simulate_dbi()) |>
summarize(
across(everything(), \(x) "test"),
.by = id
)
#> <SQL>
#> SELECT 'test' AS `id`, 'test' AS `y`, 'test' AS `z`
#> FROM `df`
#> GROUP BY `id`
Created on 2024-04-30 with reprex v2.1.0
I expect this to result in
#> <SQL>
#> SELECT `id`, 'test' AS `y`, 'test' AS `z`
#> FROM `df`
#> GROUP BY `id`
Metadata
Metadata
Assignees
Labels
No labels