Skip to content

Commit bf396ba

Browse files
committed
make unnest more robust against NULL se
1 parent a075b38 commit bf396ba

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

R/tidyr_methods.R

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,16 @@ unnest_summarized_experiment <- function(data, cols, ..., keep_empty=FALSE, pt
177177
rep(f_(se)$name, length(transcript_columns)) %>% setNames(transcript_columns)
178178
)
179179

180+
# Drop if SE is null
181+
if(data |> filter(map_lgl(!!cols, is.null)) |> nrow() > 0){
182+
warning("tidySummarizedcExperiment says: some SummarizedExperiment objects to unnest were <NULL>, and were elminated")
183+
data = data |> filter(!map_lgl(!!cols, is.null))
184+
}
185+
180186
# Do my trick to unnest
181-
return(
182-
mutate(data, !!cols := imap(
187+
data =
188+
data |>
189+
mutate(!!cols := imap(
183190
!!cols, ~ .x %>%
184191
bind_cols_internal(
185192

@@ -196,10 +203,10 @@ unnest_summarized_experiment <- function(data, cols, ..., keep_empty=FALSE, pt
196203
colnames()
197204
]
198205
)
199-
)) %>%
200-
pull(!!cols) %>%
201-
reduce(bind_rows)
202-
)
206+
))
207+
208+
# Bind
209+
return( do.call(cbind, data |> pull(!!cols)) )
203210

204211
}
205212

0 commit comments

Comments
 (0)