@@ -225,7 +225,7 @@ nest.SummarizedExperiment <- function(.data, ..., .names_sep=NULL) {
225225 # Check if the nesting is too complicated
226226 # for the moment without optimisation
227227 my_test_nest <-
228- my_data__ [1 , 1 ] %> %
228+ my_data__ [min( 1 , nrow( my_data__ )),min( 1 , ncol( my_data__ )) ] %> %
229229 as_tibble() %> %
230230 tidyr :: nest(... )
231231
@@ -279,47 +279,44 @@ nest.SummarizedExperiment <- function(.data, ..., .names_sep=NULL) {
279279 as_tibble() %> %
280280 tidyr :: nest(... ) | >
281281
282- mutate(
282+ mutate(
283283 !! as.symbol(col_name_data ) : = pmap(
284284
285- # Add sample feature to map if nesting by those
285+ # Add sample feature to map if nesting by those
286286 list (!! as.symbol(col_name_data )) %> %
287+
288+ # Check if nested by sample
289+ when(sample_name %in% colnames(my_test_nest ) ~ c(. , list (!! sample_symbol )), ~ (. )) %> %
290+
291+ # Check if nested by feature
292+ when(feature_name %in% colnames(my_test_nest ) ~ c(. , list (!! feature_symbol )), ~ (. )) , ~ {
293+
294+ # VERY COMPLICATE WAY TO DO THIS. SIMPLIFY IN THE FUTURE
295+
287296 # Check if nested by sample
288- when(sample_name %in% colnames(my_test_nest ) ~
289- c(. , list (!! sample_symbol )), ~ (. )) %> %
297+ if (sample_name %in% colnames(my_test_nest )) { my_samples = ..2 }
298+
299+ # Here I am filtering because if I have 0 samples this leads to failure
300+ else my_samples = ..1 | > filter(! is.na(!! sample_symbol )) | > pull(!! sample_symbol )
290301
291- # Check if nested by feature
292- when( feature_name %in% colnames(my_test_nest ) ~
293- c( . , list ( !! feature_symbol )), ~ ( . )), ~ {
302+ # Check if nested by feature and sample
303+ if ( sample_name %in% colnames( my_test_nest ) & feature_name %in% colnames(my_test_nest )) { my_transcripts = ..3 }
304+ else if ( feature_name %in% colnames( my_test_nest )) my_transcripts = ..2
294305
295- # VERY COMPLICATE WAY TO DO THIS.
296- # SIMPLIFY IN THE FUTURE
306+ # Here I am filtering because if I have 0 features this leads to failure
307+ else my_transcripts = ..1 | > filter( ! is.na( !! feature_symbol )) | > pull( !! feature_symbol )
297308
298- # Check if nested by sample
299- if (sample_name %in% colnames(my_test_nest )) {
300- my_samples = ..2
301- } else {
302- my_samples = pull(..1 ,!! sample_symbol )
303- }
304-
305- # Check if nested by feature and sample
306- if (sample_name %in% colnames(my_test_nest ) &
307- feature_name %in% colnames(my_test_nest )) {
308- my_transcripts = ..3
309- } else if (feature_name %in% colnames(my_test_nest )) {
310- my_transcripts = ..2
311- } else {
312- my_transcripts = pull(..1 ,!! feature_symbol )
313- }
314- # ##
315-
316- my_data__ [unique(my_transcripts ), unique(my_samples )] | >
317- select(- one_of(
318- my_nesting_column | >
319- setdiff(c(sample_name , feature_name ))
320- )) | >
321- suppressWarnings()
322- }
309+ # ##
310+
311+ my_data__ [unique(my_transcripts ),unique(my_samples )] | >
312+ select(- one_of(
313+ my_nesting_column | >
314+ setdiff(c(sample_name , feature_name ))
315+ )) | >
316+ suppressWarnings()
317+
318+
319+ }
323320 )
324321 ) %> %
325322 # Coerce to tidySummarizedExperiment_nested for unnesting
0 commit comments