Skip to content

Commit 244e2a1

Browse files
committed
add two tests, add DF conversion
1 parent 9ab4cd5 commit 244e2a1

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

R/dplyr_methods.R

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,8 @@ mutate.SummarizedExperiment <- function(.data, ...) {
404404
mutate_features <- function(.data, ...) {
405405
feature_info <- rowData(.data) |>
406406
tibble::as_tibble() |>
407-
dplyr::mutate(...)
407+
dplyr::mutate(...) |>
408+
as("DataFrame")
408409
rowData(.data) <- feature_info
409410
return(.data)
410411
}
@@ -418,13 +419,14 @@ mutate_features <- function(.data, ...) {
418419
#' @param ... extra arguments passed to dplyr::mutate
419420
#'
420421
#' @return a SummarizedExperiment with modified colData
421-
#'
422+
#'
422423
#' @export
423424
mutate_samples <- function(.data, ...) {
424-
feature_info <- colData(.data) |>
425+
sample_info <- colData(.data) |>
425426
tibble::as_tibble() |>
426-
dplyr::mutate(...)
427-
colData(.data) <- feature_info
427+
dplyr::mutate(...) |>
428+
as("DataFrame")
429+
colData(.data) <- sample_info
428430
return(.data)
429431
}
430432

tests/testthat/test-dplyr_methods.R

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,3 +205,21 @@ test_that("group_split splits with mutliple arguments", {
205205
length() |>
206206
expect_equal(4)
207207
})
208+
209+
test_that("mutate features", {
210+
pasilla %>%
211+
mutate_features(new = 1:nrow(pasilla)) %>%
212+
rowData() %>%
213+
as_tibble() %>%
214+
pull(new) %>%
215+
expect_equal(1:nrow(pasilla))
216+
})
217+
218+
test_that("mutate samples", {
219+
pasilla %>%
220+
mutate_samples(new = 1:ncol(pasilla)) %>%
221+
colData() %>%
222+
as_tibble() %>%
223+
pull(new) %>%
224+
expect_equal(1:ncol(pasilla))
225+
})

0 commit comments

Comments
 (0)