@@ -103,24 +103,77 @@ NULL
103103bind_cols_internal = function (... , .id = NULL , column_belonging = NULL ) {
104104 tts <- tts <- flatten_if(dots_values(... ), is_spliced )
105105
106- tts [[1 ]] | >
107- as_tibble(skip_GRanges = TRUE ) | >
108- dplyr :: bind_cols(tts [[2 ]], .id = .id ) %> %
109- when(
110-
111- # If the column added are not sample-wise or feature-wise return tibble
112- (colnames(tts [[2 ]]) %in% c(
113- get_subset_columns(. , !! s_(tts [[1 ]])$ symbol ),
114- get_subset_columns(. , !! f_(tts [[1 ]])$ symbol )
115- )
116- ) | > all() ~ update_SE_from_tibble(. , tts [[1 ]], column_belonging = column_belonging ),
117-
118- # Return tiblle
119- ~ {
120- warning(" tidySummarizedExperiment says: The new columns do not include pure sample-wise or feature-wise. A data frame is returned for independent data analysis." )
121- (. )
122- }
123- )
106+ # If I have column corresponding bind directly
107+ # Without tranformation to tibble
108+ if (! is.null(column_belonging )){
109+
110+ # For colData
111+ colData_additions = column_belonging [column_belonging == s_(tts [[1 ]] )$ name ] | > names()
112+
113+ data_frame_to_attach =
114+ tts [[1 ]] | >
115+ select(!! s_(tts [[1 ]] )$ symbol ) | >
116+ suppressMessages() | >
117+ bind_cols(tts [[2 ]] | > select(all_of(colData_additions ))) | >
118+ distinct()
119+
120+ # Set row names
121+ data_frame_to_attach =
122+ data_frame_to_attach | >
123+ select(- 1 ) | >
124+ DataFrame(row.names = data_frame_to_attach | > pull(1 ))
125+
126+ # Reorder
127+ data_frame_to_attach = data_frame_to_attach [match(rownames(data_frame_to_attach ), colnames(tts [[1 ]])), , drop = FALSE ]
128+
129+ # Attach
130+ colData(tts [[1 ]]) = cbind(colData(tts [[1 ]]), data_frame_to_attach )
131+
132+ # For rowData
133+ rowData_additions = column_belonging [column_belonging == f_(tts [[1 ]] )$ name ] | > names()
134+
135+ data_frame_to_attach =
136+ tts [[1 ]] | >
137+ select(!! f_(tts [[1 ]] )$ symbol ) | >
138+ suppressMessages() | >
139+ bind_cols(tts [[2 ]] | > select(all_of(rowData_additions ))) | >
140+ distinct()
141+
142+ # Set row names
143+ data_frame_to_attach =
144+ data_frame_to_attach | >
145+ select(- 1 ) | >
146+ DataFrame(row.names = data_frame_to_attach | > pull(1 ))
147+
148+ # Reorder
149+ data_frame_to_attach = data_frame_to_attach [match(rownames(data_frame_to_attach ), rownames(tts [[1 ]])), , drop = FALSE ]
150+
151+ # Attach
152+ rowData(tts [[1 ]]) = cbind(rowData(tts [[1 ]]), data_frame_to_attach )
153+
154+ tts [[1 ]]
155+ }
156+
157+ # If I DON'T have column corresponding go through tibble
158+ else
159+ tts [[1 ]] | >
160+ as_tibble(skip_GRanges = TRUE ) | >
161+ dplyr :: bind_cols(tts [[2 ]], .id = .id ) %> %
162+ when(
163+
164+ # If the column added are not sample-wise or feature-wise return tibble
165+ (colnames(tts [[2 ]]) %in% c(
166+ get_subset_columns(. , !! s_(tts [[1 ]])$ symbol ),
167+ get_subset_columns(. , !! f_(tts [[1 ]])$ symbol )
168+ )
169+ ) | > all() ~ update_SE_from_tibble(. , tts [[1 ]], column_belonging = column_belonging ),
170+
171+ # Return tiblle
172+ ~ {
173+ warning(" tidySummarizedExperiment says: The new columns do not include pure sample-wise or feature-wise. A data frame is returned for independent data analysis." )
174+ (. )
175+ }
176+ )
124177}
125178
126179bind_cols_ = function (... , .id = NULL ) { bind_cols_internal(... , .id = NULL ) }
0 commit comments