From 062ddab5f388ed457920bdb47ba9db309268ce5e Mon Sep 17 00:00:00 2001 From: stemangiola Date: Sun, 5 Sep 2021 10:05:26 +1000 Subject: [PATCH] add dedicated function for tibble objects --- R/tidyr_methods.R | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/R/tidyr_methods.R b/R/tidyr_methods.R index d349380..716b6c4 100755 --- a/R/tidyr_methods.R +++ b/R/tidyr_methods.R @@ -59,8 +59,8 @@ NULL #' #' #' @export -unnest.tidySingleCellExperiment_nested <- function(data, cols, ..., keep_empty=FALSE, ptype=NULL, - names_sep=NULL, names_repair="check_unique", .drop, .id, .sep, .preserve) { +unnest_single_cell_experiment <- function(data, cols, ..., keep_empty=FALSE, ptype=NULL, + names_sep=NULL, names_repair="check_unique", .drop, .id, .sep, .preserve) { # Need this otherwise crashes map .data_ <- data @@ -75,16 +75,16 @@ unnest.tidySingleCellExperiment_nested <- function(data, cols, ..., keep_empty=F is("SingleCellExperiment") %>% any() ~ - # Do my trick to unnest - mutate(., !!cols := imap( - !!cols, ~ .x %>% - bind_cols_( + # Do my trick to unnest + mutate(., !!cols := imap( + !!cols, ~ .x %>% + bind_cols_( - # Attach back the columns used for nesting - .data_ %>% select(-!!cols) %>% slice(rep(.y, nrow(as_tibble(.x)))) + # Attach back the columns used for nesting + .data_ %>% select(-!!cols) %>% slice(rep(.y, nrow(as_tibble(.x)))) - ) - )) %>% + ) + )) %>% pull(!!cols) %>% reduce(bind_rows), @@ -96,6 +96,15 @@ unnest.tidySingleCellExperiment_nested <- function(data, cols, ..., keep_empty=F ) } +#' @importFrom rlang quo_name +#' @importFrom purrr imap +#' +#' +#' @export +unnest.tidySingleCellExperiment_nested <- unnest_single_cell_experiment + + + #' nest #' #' @importFrom tidyr nest