From b6b237419627ef11406ff93f934eecdcfd918ea9 Mon Sep 17 00:00:00 2001 From: LTLA Date: Tue, 28 Nov 2023 23:48:10 -0800 Subject: [PATCH] Further fixes to pass CHECK. --- DESCRIPTION | 3 +-- R/saveSummarizedExperiment.R | 6 +++++- tests/testthat/test-SummarizedExperiment.R | 13 ++++++++++--- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 0a02848..9096979 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -25,8 +25,7 @@ Suggests: rmarkdown, knitr, testthat, - BiocStyle, - jsonlite + BiocStyle VignetteBuilder: knitr RoxygenNote: 7.2.3 biocViews: diff --git a/R/saveSummarizedExperiment.R b/R/saveSummarizedExperiment.R index c215b38..f9933b8 100644 --- a/R/saveSummarizedExperiment.R +++ b/R/saveSummarizedExperiment.R @@ -73,7 +73,11 @@ setMethod("saveObject", "SummarizedExperiment", function(x, path, summarizedexpe adir <- file.path(path, "assays") dir.create(adir) ass.names <- assayNames(x) - if (anyDuplicated(ass.names)) { + if (is.null(ass.names)) { + stop("assays should be named") + } else if (any(ass.names == "")) { + stop("assays should have non-empty names") + } else if (anyDuplicated(ass.names)) { stop("assays should be uniquely named") } write(toJSON(ass.names), file=file.path(adir, "names.json")) diff --git a/tests/testthat/test-SummarizedExperiment.R b/tests/testthat/test-SummarizedExperiment.R index 390f61b..150a3da 100644 --- a/tests/testthat/test-SummarizedExperiment.R +++ b/tests/testthat/test-SummarizedExperiment.R @@ -151,19 +151,26 @@ test_that("stageObject fails when the assay names are NULL or non-unique", { assays(se) <- ass expect_error(stageObject(se, tmp, "rnaseq"), "should be named") + tmp <- tempfile() + expect_error(saveObject(se, tmp), "should be named") + + # Duplicated tmp <- tempfile() dir.create(tmp) - assayNames(se) <- rep("FOO", length(assayNames(se))) + assayNames(se) <- rep("FOO", length(assays(se))) expect_error(stageObject(se, tmp, "rnaseq"), "duplicate") + tmp <- tempfile() + expect_error(saveObject(se, tmp), "unique") + + # Empty. tmp <- tempfile() dir.create(tmp) assayNames(se) <- c("", head(LETTERS, length(assayNames(se)) - 1)) expect_error(stageObject(se, tmp, "rnaseq"), "empty") - # Fails in the new world. tmp <- tempfile() - expect_error(saveObject(se, tmp), "uniquely named") + expect_error(saveObject(se, tmp), "empty") }) test_that("stageObject works with the various types of vectors", {