diff --git a/R/MultiAssayExperiment-helpers.R b/R/MultiAssayExperiment-helpers.R index be28e4d..a1a3493 100644 --- a/R/MultiAssayExperiment-helpers.R +++ b/R/MultiAssayExperiment-helpers.R @@ -351,9 +351,12 @@ setMethod("mergeReplicates", "ANY", if (!requireNamespace("reshape2", quietly = TRUE)) stop("Package 'reshape2' is required for 'longFormat()' conversion") - reshape2::melt( + res <- reshape2::melt( object, varnames = c("rowname", "colname"), value.name = "value" ) + if (!is.character(res[["rowname"]])) + res[["rowname"]] <- as.character(res[["rowname"]]) + res } .longFormatElist <- function(object, i) { diff --git a/tests/testthat/test-MultiAssayExperiment-helpers.R b/tests/testthat/test-MultiAssayExperiment-helpers.R index a675440..6fc512f 100644 --- a/tests/testthat/test-MultiAssayExperiment-helpers.R +++ b/tests/testthat/test-MultiAssayExperiment-helpers.R @@ -254,4 +254,19 @@ test_that(".longFormatANY works", { Reduce(union, rownames(miniACC)) ) ) + + m <- matrix(1:12, nrow = 4) + colnames(m) <- LETTERS[1:3] + se <- SummarizedExperiment(m) + rownames(se) <- c(1, 2, 4, 5) + + mae <- MultiAssayExperiment(list(x = se)) + longformat <- longFormat(mae) + expect_true( + is.character(longformat[["rowname"]]) + ) + expect_identical( + typeof(m), + typeof(longformat[["value"]]) + ) })