Skip to content

Commit 8ded0a0

Browse files
committed
A few fixes seem old, except line 154
1 parent acd69f1 commit 8ded0a0

File tree

2 files changed

+76
-23
lines changed

2 files changed

+76
-23
lines changed

R/dplyr_methods.R

Lines changed: 71 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -103,24 +103,77 @@ NULL
103103
bind_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

126179
bind_cols_ = function(..., .id=NULL) { bind_cols_internal(..., .id=NULL) }

R/tidyr_methods.R

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,9 @@ unnest_summarized_experiment <- function(data, cols, ..., keep_empty=FALSE, pt
163163

164164
# Mark if columns belong to feature or sample
165165
my_unnested_tibble =
166-
mutate(data, !!cols := map(!!cols, ~ as_tibble(.x))) %>%
167-
168-
select(-suppressWarnings( one_of(s_(my_se)$name, f_(my_se)$name))) %>%
166+
data |>
167+
mutate(!!cols := map(!!cols, ~ as_tibble(.x))) |>
168+
select(-any_of(c(s_(my_se)$name, f_(my_se)$name))) |>
169169
unnest(!!cols)
170170

171171
# Get which column is relative to feature or sample
@@ -197,14 +197,14 @@ unnest_summarized_experiment <- function(data, cols, ..., keep_empty=FALSE, pt
197197

198198
# Attach back the columns used for nesting
199199
.data_ %>%
200-
select(-!!cols, -suppressWarnings( one_of(s_(my_se)$name, f_(my_se)$name))) %>%
200+
select(-!!cols, -any_of(c(s_(my_se)$name, f_(my_se)$name))) %>%
201201
slice(rep(as.integer(.y), ncol(.x) * nrow(.x))),
202202

203203
# Column sample-wise or feature-wise
204204
column_belonging =
205205
source_column[
206206
.data_ %>%
207-
select(-!!cols, -suppressWarnings( one_of(s_(my_se)$name, f_(my_se)$name))) %>%
207+
select(-!!cols, -any_of(c(s_(my_se)$name, f_(my_se)$name))) %>%
208208
colnames()
209209
]
210210
)

0 commit comments

Comments
 (0)