Skip to content

Commit 7e89588

Browse files
committed
handle .keep and logical comparisons
1 parent 1bacc77 commit 7e89588

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

R/dplyr_methods.R

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -882,9 +882,27 @@ group_split.SummarizedExperiment <- function(.tbl, ..., .keep = TRUE) {
882882
var_list <- enquos(...)
883883
data_nested <- NULL
884884

885-
.tbl |>
885+
nested <- .tbl |>
886886
mutate(!!!var_list) |>
887-
nest(data_nested = - (!!!var_list)) |>
888-
pull(data_nested)
887+
nest(data_nested = -(substring(as.character(var_list), 2)))
889888

889+
if(.keep) {
890+
grouped_data <- nested |>
891+
pull(data_nested)
892+
893+
grouping_cols <- nested |>
894+
select(substring(as.character(var_list), 2))
895+
896+
for(i in 1:length(grouped_data)) {
897+
grouped_data[[i]] <- grouped_data[[i]] |>
898+
mutate(grouping_cols[i,])
899+
}
900+
901+
grouped_data
902+
903+
} else {
904+
nested |>
905+
pull(data_nested)
906+
}
907+
890908
}

0 commit comments

Comments
 (0)