-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
vctrs:: based summarise() filter() slice() mutate() #4523
Conversation
…tipleVectorVisitors c++class
Could replace map_int(x, vec_size) by vec_sizes() from r-lib/vctrs#539
Potential library(dplyr, warn.conflicts = FALSE)
library(rlang)
library(purrr, warn.conflicts = FALSE)
library(vctrs)
summarise_data_mask <- function(data, rows) {
chunks_env <- env()
map2(data, names(data), function(col, nm) {
env_bind_lazy(chunks_env, !!nm := map(rows, vec_slice, x = col))
})
bottom <- env()
column_names <- set_names(names(data))
.current_group_index <- NA_integer_
env_bind_active(bottom, !!!map(column_names, function(column) {
function() {
chunks_env[[column]][[.current_group_index]]
}
}))
mask <- new_data_mask(bottom)
mask$.set_current_group <- function(group_index) {
.current_group_index <<- group_index
}
mask
}
summarise_one <- function(data, expr, env = caller_env()) {
expr <- enquo(expr)
rows <- group_rows(data)
mask <- summarise_data_mask(data, rows)
map(seq_along(rows), function(group) {
mask$.set_current_group(group)
eval_tidy(expr, mask, env = env)
})
}
data <- iris %>% group_by(Species)
summarise_one(data,
mean(Sepal.Length)
)
#> [[1]]
#> [1] 5.006
#>
#> [[2]]
#> [1] 5.936
#>
#> [[3]]
#> [1] 6.588
summarise_one(data,
tibble(mean = mean(Sepal.Length), median = median(Sepal.Length))
)
#> [[1]]
#> # A tibble: 1 x 2
#> mean median
#> <dbl> <dbl>
#> 1 5.01 5
#>
#> [[2]]
#> # A tibble: 1 x 2
#> mean median
#> <dbl> <dbl>
#> 1 5.94 5.9
#>
#> [[3]]
#> # A tibble: 1 x 2
#> mean median
#> <dbl> <dbl>
#> 1 6.59 6.5
vec_c(!!!summarise_one(data,
mean(Sepal.Length)
))
#> [1] 5.006 5.936 6.588
vec_c(!!!summarise_one(data,
tibble(mean = mean(Sepal.Length), median = median(Sepal.Length))
))
#> mean median
#> 1 5.006 5.0
#> 2 5.936 5.9
#> 3 6.588 6.5 Also, in addition to |
…rest of the code and reinject it later on
vctrs based versions of summarise(), mutate(), filter() and slice()
vctrs based versions of summarise(), mutate(), filter() and slice()
vctrs based versions of summarise(), mutate(), filter() and slice()
vctrs based versions of summarise(), mutate(), filter() and slice()
vctrs based versions of summarise(), mutate(), filter() and slice()
vctrs based versions of summarise(), mutate(), filter() and slice()
vctrs based versions of summarise(), mutate(), filter() and slice()
vctrs based versions of summarise(), mutate(), filter() and slice()
vctrs based versions of summarise(), mutate(), filter() and slice()
vctrs based versions of summarise(), mutate(), filter() and slice()
vctrs based versions of summarise(), mutate(), filter() and slice()
vctrs based versions of summarise(), mutate(), filter() and slice()
This old issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with reprex) and link to this issue. https://reprex.tidyverse.org/ |
Not quite ready yet, but experimental
summarise2()
has some 💪 :Created on 2019-08-07 by the reprex package (v0.3.0.9000)