Skip to content

Commit

Permalink
Further fixes to pass CHECK.
Browse files Browse the repository at this point in the history
  • Loading branch information
LTLA committed Nov 29, 2023
1 parent c26fb74 commit b6b2374
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
3 changes: 1 addition & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ Suggests:
rmarkdown,
knitr,
testthat,
BiocStyle,
jsonlite
BiocStyle
VignetteBuilder: knitr
RoxygenNote: 7.2.3
biocViews:
Expand Down
6 changes: 5 additions & 1 deletion R/saveSummarizedExperiment.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
13 changes: 10 additions & 3 deletions tests/testthat/test-SummarizedExperiment.R
Original file line number Diff line number Diff line change
Expand Up @@ -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", {
Expand Down

0 comments on commit b6b2374

Please sign in to comment.