@@ -219,6 +219,14 @@ nest.SummarizedExperiment <- function(.data, ..., .names_sep=NULL) {
219219 .data <- ping_old_special_column_into_metadata(.data )
220220 }
221221
222+ # if the data does not have raw, names or clumn names
223+ # we have to add them, otherwise the nesting and a nesting will get confused with
224+ # the link between Sample wise, columns, and Sample IDs
225+ if (rownames(.data ) | > is.null() | colnames(.data ) | > is.null() )
226+ warning(" tidySummarizedExperiment says: the nesting and unnesting operations require row names and column names to avoid side-effects. Therefore, doors will be added as \" 1\" , \" 2\" , \" 3\" ." )
227+ if (rownames(.data ) | > is.null() ) rownames(.data ) = .data | > nrow() | > seq_len() | > as.character()
228+ if (colnames(.data ) | > is.null() ) colnames(.data ) = .data | > ncol() | > seq_len() | > as.character()
229+
222230 my_data__ <- .data
223231
224232 # Names
@@ -256,12 +264,6 @@ nest.SummarizedExperiment <- function(.data, ..., .names_sep=NULL) {
256264 " We are working for optimising a generalised solution of nest()." )
257265 }
258266
259- # my_data__nested <-
260- # my_data__ %>%
261- # # This is needed otherwise nest goes into loop and fails
262- # as_tibble() %>%
263- # tidyr::nest(...)
264-
265267 # If I nest only for .feature -> THIS WORKS ONLY WITH THE CHECK ABOVE
266268 if (feature_name %in% colnames(my_test_nest )) {
267269 return (
@@ -280,7 +282,7 @@ nest.SummarizedExperiment <- function(.data, ..., .names_sep=NULL) {
280282
281283
282284 my_data__ %> %
283- select(!! sample_symbol , !! feature_symbol , my_nesting_column ) | >
285+ select(!! sample_symbol , !! feature_symbol , all_of( my_nesting_column ) ) | >
284286 as_tibble() %> %
285287 tidyr :: nest(... ) | >
286288
@@ -311,15 +313,18 @@ nest.SummarizedExperiment <- function(.data, ..., .names_sep=NULL) {
311313 # Here I am filtering because if I have 0 features this leads to failure
312314 else my_transcripts = ..1 | > filter(! is.na(!! feature_symbol )) | > pull(!! feature_symbol )
313315
314- # ##
315-
316+ # if the summarised experiment does not have feature ID or Sample ID,
317+ # convert back those to integers
318+ # Note to self: this is convoluted, because if feature ID and sample ID
319+ # were to stay integers all along, these will not be needed
320+ if (rownames(my_data__ ) | > is.null()) my_transcripts = as.integer(my_transcripts )
321+ if (colnames(my_data__ ) | > is.null()) my_samples = as.integer(my_samples )
322+
316323 my_data__ [unique(my_transcripts ),unique(my_samples )] | >
317- select(- one_of (
324+ select(- any_of (
318325 my_nesting_column | >
319326 setdiff(c(sample_name , feature_name ))
320- )) | >
321- suppressWarnings()
322-
327+ ))
323328
324329 }
325330 )
0 commit comments