Skip to content
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

group_split #80

Merged
merged 6 commits into from
Dec 10, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
add group_split
  • Loading branch information
B0ydT committed Dec 10, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit d1868103da8e937663e4f3358694cb371378bc53
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -13,6 +13,7 @@ S3method(full_join,Seurat)
S3method(ggplot,Seurat)
S3method(glimpse,tidyseurat)
S3method(group_by,Seurat)
S3method(group_split,Seurat)
S3method(inner_join,Seurat)
S3method(join_transcripts,Seurat)
S3method(join_transcripts,default)
@@ -71,6 +72,7 @@ importFrom(dplyr,filter)
importFrom(dplyr,full_join)
importFrom(dplyr,group_by)
importFrom(dplyr,group_by_drop_default)
importFrom(dplyr,group_rows)
importFrom(dplyr,inner_join)
importFrom(dplyr,left_join)
importFrom(dplyr,mutate)
37 changes: 37 additions & 0 deletions R/dplyr_methods.R
Original file line number Diff line number Diff line change
@@ -966,3 +966,40 @@ pull.Seurat <- function(.data, var=-1, name=NULL, ...) {
as_tibble() %>%
dplyr::pull( var=!!var, name=!!name, ...)
}

#' @name group_split
#' @rdname group_split
#' @inherit dplyr::group_split
#'
#' @examples
#' data(pbmc_small)
#' pbmc_small |> group_split(groups)
#'
#' @importFrom ellipsis check_dots_used
#' @importFrom dplyr group_by
#' @importFrom dplyr group_rows
#' @export
group_split.Seurat <- function(.tbl, ..., .keep = TRUE) {

var_list <- enquos(...)

group_list <- .tbl |>
as_tibble() |>
dplyr::group_by(!!!var_list)

groups <- group_list |>
dplyr::group_rows()

v <- vector(mode = "list", length = length(groups))

for (i in seq_along(v)) {
v[[i]] <- .tbl[,groups[[i]]]

if(.keep == FALSE) {
v[[i]] <- select(v[[i]], !(!!!var_list))
}
}

v

}
64 changes: 64 additions & 0 deletions man/group_split.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/slice.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.