These two lines give identical results, but the second one leads to an error in the call:
list(a = 1, b = 2, c = 3, d = 4) %>% unlist()
#> a b c d
#> 1 2 3 4
lapply(c(a = 1, b = 2, c = 3, d = 4), function(b) b[[1]]) %>% unlist()
#> a b c d
#> 1 2 3 4
See here:
library(tidytable)
.data <- tidytable(x = 1:10, y = 1)
.data %>%
summarize(across(
all_of("x"),
function(y) {
list(a = 1, b = 2, c = 3, d = 4) %>% unlist()
}
), .by = "y")
#> # A tidytable: 4 × 2
#> y x
#> <dbl> <dbl>
#> 1 1 1
#> 2 1 2
#> 3 1 3
#> 4 1 4
.data %>%
summarize(across(
all_of("x"),
function(y) {
lapply(c(a = 1, b = 2, c = 3, d = 4), function(b) b[[1]]) %>% unlist()
}
), .by = "y")
#> Error in replace_dot_alias(e[[i]]): badly formed function expression
These two lines give identical results, but the second one leads to an error in the call:
See here:
Created on 2024-01-26 with reprex v2.0.2