Skip to content

Commit b28d704

Browse files
committed
validate layer lists are named; fix SD constructor
1 parent 8d5c18c commit b28d704

2 files changed

Lines changed: 21 additions & 6 deletions

File tree

R/SpatialData.R

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,8 @@ SpatialData <- \(
6060
shapes=list(),
6161
tables=list())
6262
{
63-
.SpatialData(
64-
images=sdImageList(images),
65-
labels=sdLabelList(labels),
66-
points=sdPointList(points),
67-
shapes=sdShapeList(shapes),
68-
tables=sdTableList(tables))
63+
sd <- .SpatialData()
64+
for (l in .LAYERS)
65+
sd[[l]] <- get(l)
66+
return(sd)
6967
}

R/validity.R

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,26 @@ setValidity2("SpatialDataPoint", .validatePoint)
101101
#' @importFrom S4Vectors setValidity2
102102
setValidity2("SpatialDataShape", .validateShape)
103103

104+
.nm <- \(x, l) {
105+
msg <- c()
106+
lys <- get(l)(x)
107+
nms <- names(lys)
108+
typ <- class(lys)[[1]]
109+
if (is.null(nms)) {
110+
msg <- c(msg, sprintf("'%s' missing names", typ))
111+
} else {
112+
na <- nchar(nms) == 0
113+
if (any(na)) {
114+
msg <- c(msg, sprintf("'%s' elements %s missing names", typ, which(na)))
115+
}
116+
}
117+
return(msg)
118+
}
119+
104120
#' @importFrom methods is
105121
.validateSpatialData <- \(x) {
106122
msg <- c()
123+
for (l in .LAYERS) msg <- c(msg, .nm(x, l))
107124
# TODO: validate .zattrs across all layers
108125
for (y in as.list(labels(x))) msg <- c(msg, .validateLabel(y))
109126
for (y in as.list(images(x))) msg <- c(msg, .validateImage(y))

0 commit comments

Comments
 (0)