Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#151 #154

Merged
merged 1 commit into from
Jun 20, 2024
Merged

#151 #154

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Package: SpatialExperiment
Version: 1.15.0
Version: 1.15.1
Title: S4 Class for Spatially Resolved -omics Data
Description: Defines an S4 class for storing data from spatial -omics experiments.
The class extends SingleCellExperiment to
Expand Down
11 changes: 10 additions & 1 deletion R/imgData-utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,17 @@
# - NULL return first available entry
# - character string returns matching entry(ies)
.get_img_idx <- function(x, sample_id=NULL, image_id=NULL) {
# TODO: validity checks
img <- imgData(x)
for (i in c("sample_id", "image_id")) {
j <- get(i)
if (is.factor(j) || is.numeric(j))
assign(i, as.character(j))
if (!(is.null(j) || j %in% img[[i]] ||
length(j) == 1 && is.logical(j)))
stop(sprintf(c(
"'%s' invalid; should be NULL, TRUE/FALSE,",
" or matching entries in imgData(.)$%s"), i))
}
if (is.character(sample_id) && is.character(image_id)) {
sid <- img$sample_id == sample_id
iid <- img$image_id == image_id
Expand Down
10 changes: 10 additions & 0 deletions tests/testthat/test_imgData-methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@ test_that("getImg,sample_id=image_id=TRUE returns a list", {
expect_identical(x, y)
})

test_that("getImg handles non-character sample/image_id (#151)", {
. <- (spe$sample_id <- factor(spe$sample_id))[1]
expect_silent(getImg(spe, sample_id=.))
. <- (spe$sample_id <- as.integer(spe$sample_id))[1]
expect_silent(getImg(spe, sample_id=.))
. <- imgData(spe)$image_id <- 1
expect_silent(getImg(spe, image_id=.))
expect_silent(getImg(spe, image_id=as.factor(.)))
})

# addImg -----------------------------------------------------------------------

test_that("addImg for existing sample_id,image_id throws error", {
Expand Down
Loading