Skip to content

Commit 51164d7

Browse files
authored
clean R CMD check
2 parents a8ba9ac + 9005530 commit 51164d7

30 files changed

Lines changed: 794 additions & 734 deletions

‎R/CTutils.R‎

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,21 @@ setMethod("CTname", "SpatialDataAttrs", \(x, ...) {
103103

104104
# SpatialDataElement ----
105105

106-
.SDE_METS <- c("axes", "CTlist", "CTtype", "CTname")
107-
for (. in .SDE_METS) {
108-
setMethod(., "SpatialDataElement",
109-
eval(parse(text=sprintf("\\(x, ...) %s(meta(x), ...)", .))))
110-
}
106+
#' @rdname CTutils
107+
#' @export
108+
setMethod("axes", "SpatialDataElement", \(x, ...) axes(meta(x), ...))
109+
110+
#' @rdname CTutils
111+
#' @export
112+
setMethod("CTlist", "SpatialDataElement", \(x, ...) CTlist(meta(x), ...))
113+
114+
#' @rdname CTutils
115+
#' @export
116+
setMethod("CTtype", "SpatialDataElement", \(x, ...) CTtype(meta(x), ...))
117+
118+
#' @rdname CTutils
119+
#' @export
120+
setMethod("CTname", "SpatialDataElement", \(x, ...) CTname(meta(x), ...))
111121

112122
#' @rdname CTutils
113123
#' @export
@@ -185,7 +195,6 @@ setMethod("addCT", "SpatialDataElement",
185195
#' @rdname CTutils
186196
#' @export
187197
setMethod("addCT", "SpatialDataAttrs", \(x, name, type="identity", data=NULL) {
188-
#x <- meta(image(sd, 2)); name <- "lowres"; type="identity"; data=NULL
189198
stopifnot(
190199
is.character(name), length(name) == 1,
191200
is.character(type), length(type) == 1)

‎R/SDattrs.R‎

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,23 @@
11
#' @name SpatialDataAttrs
22
#' @title The `SpatialDataAttrs` class
33
#'
4+
#' @aliases region region<-
5+
#' @aliases regions regions<-
6+
#' @aliases instances instances<-
7+
#' @aliases region_key region_key<-
8+
#' @aliases feature_key feature_key<-
9+
#' @aliases instance_key instance_key<-
10+
#'
411
#' @param x element or list extracted from a OME-NGFF compliant .zattrs file.
512
#' @param name character string for extraction (see ?base::`$`).
613
#' @param type character string; either "array" (image/label) or "frame" (point/shape).
7-
#' @param axes list of axes; if NULL, defaults to cyx (array) or xy (frame).
8-
#' @param transformations list of transformations; if NULL, defaults to global identity.
14+
#' @param label flag; when \code{type="frame"}, should attributes be for a label?
15+
#' @param trans list of coordinate transformations; defaults to identity only.
16+
#' @param value character string (for one \code{region} and \code{_key}s),
17+
#' or vector (for many \code{region}s, \code{instances} and \code{regions}).
18+
#' @param ver character string; specified the .zarr version to comply with.
19+
#' @param nch scalar integer; how many channels should there be?
20+
#' (ignored unless \code{type="frame"} and \code{label=FALSE}).
921
#' @param ... additional attributes (e.g., version, feature_key).
1022
#'
1123
#' @details
@@ -42,12 +54,12 @@
4254
#' # constructor
4355
#' SpatialDataAttrs(type="frame")
4456
#' SpatialDataAttrs(type="array")
45-
#' SpatialDataAttrs(type="array", n=7)
57+
#' SpatialDataAttrs(type="array", nch=7)
4658
#' SpatialDataAttrs(type="array", label=TRUE)
4759
#'
4860
#' @export
4961
SpatialDataAttrs <- \(x, type=c("array", "frame"),
50-
label=FALSE, trans=NULL, ver="0.4", n=3, ...)
62+
label=FALSE, trans=NULL, ver="0.4", nch=3, ...)
5163
{
5264
if (!missing(x)) return(.SpatialDataAttrs(x))
5365
type <- match.arg(type)
@@ -68,7 +80,7 @@ SpatialDataAttrs <- \(x, type=c("array", "frame"),
6880
if (type == "array") {
6981
# default structure
7082
res <- list(
71-
omero=list(channels=list(label=letters[seq_len(n)])),
83+
omero=list(channels=list(label=letters[seq_len(nch)])),
7284
multiscales=list(list(
7385
axes=ax,
7486
version="0.4",
@@ -126,20 +138,10 @@ setMethod("$", "SpatialDataAttrs", \(x, name) x[[name]])
126138
#' @noRd
127139
.ms <- \(x) switch(.zv(x), "0.3"=x$ome$multiscales, x$multiscales)
128140

129-
# internal use only!
130-
#' @noRd
131-
.ch <- \(x) {
132-
if (.zv(x) == "0.3") x <- x$ome
133-
unlist(x$omero$channels)
134-
}
135-
136141
# internal use only!
137142
#' @noRd
138143
setMethod("multiscales", "list", .ms)
139144

140-
#' @export
141-
setMethod("channels", "SpatialDataAttrs", \(x, ...) .ch(x))
142-
143145
# features ----
144146

145147
#' @export

‎R/SpatialData.R‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,24 @@
11
#' @name SpatialData
22
#' @title The `SpatialData` class
33
#'
4-
#' @description ...
4+
#' @aliases data meta layer element
5+
#' @aliases image label point shape table
6+
#' @aliases images labels points shapes tables
7+
#' @aliases image<- label<- point<- shape<- table<-
8+
#' @aliases images<- labels<- points<- shapes<- tables<-
9+
#' @aliases imageNames labelNames pointNames shapeNames tableNames
10+
#' @aliases imageNames<- labelNames<- pointNames<- shapeNames<- tableNames<-
11+
#' @aliases [[<-,SpatialData,character,ANY-method
12+
#' @aliases [[<-,SpatialData,numeric,ANY-method
13+
#'
14+
#' @description
15+
#' \code{SpatialData} provides an R interface to Python's \code{spatialdata},
16+
#' which enables the representation of diverse spatial omics datasets using
17+
#' the OME-NGFF (Next Generation File Format) standard. In R,
18+
#' \itemize{
19+
#' \item images and labels are \code{ZarrArray}s (\code{Rarr} package).
20+
#' \item points and shapes are managed using \code{duckspatial} tables.
21+
#' \item tables are \code{SingleCellExperiment}s (read with \code{anndataR}).}
522
#'
623
#' @param images list of \code{\link{SpatialDataImage}}s
724
#' @param labels list of \code{\link{SpatialDataLabel}}s

‎R/combine.R‎

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -17,42 +17,42 @@
1717
#' imageNames(y)
1818
#' region(table(y, 1))
1919
#' region(table(y, 2))
20-
#'
21-
#' @importFrom BiocGenerics combine
20+
NULL
21+
2222
#' @export
23-
setMethod("combine",
24-
c("SpatialData", "SpatialData"),
25-
\(x, y, ...) {
26-
# ensure element names are unique across objects
27-
old <- list(unlist(colnames(x)), unlist(colnames(y)))
28-
idx <- rep.int(c(1, 2), vapply(old, length, integer(1)))
29-
new <- split(make.unique(unlist(old)), idx)
30-
for (i in c(1, 2)) {
31-
z <- get(c("x", "y")[i])
32-
layer_nms <- setdiff(rownames(z), "tables")
33-
old_nms <- unlist(colnames(z)[layer_nms])
34-
# find new names for these elements
35-
j <- match(old_nms, old[[i]])
36-
new_nms <- new[[i]][j]
37-
38-
# rename elements
39-
for (l in layer_nms) {
40-
j <- match(names(z[[l]]), old[[i]])
41-
names(z[[l]]) <- new[[i]][j]
42-
}
43-
# sync tables
44-
z <- .sync_tables(z, old_nms, new_nms)
45-
46-
# rename tables themselves
47-
j <- match(tableNames(z), old[[i]])
48-
tableNames(z) <- new[[i]][j]
49-
50-
assign(c("x", "y")[i], z)
23+
#' @rdname combine
24+
#' @importFrom BiocGenerics combine
25+
setMethod("combine", c("SpatialData", "SpatialData"), \(x, y, ...) {
26+
# ensure element names are unique across objects
27+
old <- list(unlist(colnames(x)), unlist(colnames(y)))
28+
idx <- rep.int(c(1, 2), vapply(old, length, integer(1)))
29+
new <- split(make.unique(unlist(old)), idx)
30+
for (i in c(1, 2)) {
31+
z <- get(c("x", "y")[i])
32+
layer_nms <- setdiff(rownames(z), "tables")
33+
old_nms <- unlist(colnames(z)[layer_nms])
34+
# find new names for these elements
35+
j <- match(old_nms, old[[i]])
36+
new_nms <- new[[i]][j]
37+
38+
# rename elements
39+
for (l in layer_nms) {
40+
j <- match(names(z[[l]]), old[[i]])
41+
names(z[[l]]) <- new[[i]][j]
5142
}
52-
SpatialData(
53-
images=c(x$images, y$images),
54-
labels=c(x$labels, y$labels),
55-
points=c(x$points, y$points),
56-
shapes=c(x$shapes, y$shapes),
57-
tables=c(x$tables, y$tables))
58-
})
43+
# sync tables
44+
z <- .sync_tables(z, old_nms, new_nms)
45+
46+
# rename tables themselves
47+
j <- match(tableNames(z), old[[i]])
48+
tableNames(z) <- new[[i]][j]
49+
50+
assign(c("x", "y")[i], z)
51+
}
52+
SpatialData(
53+
images=c(x$images, y$images),
54+
labels=c(x$labels, y$labels),
55+
points=c(x$points, y$points),
56+
shapes=c(x$shapes, y$shapes),
57+
tables=c(x$tables, y$tables))
58+
})

‎R/mask.R‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ setMethod(".mask", c("SpatialDataShape", "SpatialDataShape"), \(i, j, how=NULL,
163163
if (nrow(collect(head(ij, 1))) == 0)
164164
stop("found no intersections",
165165
" between shapes 'i' and 'j'")
166+
id_x <- id_y <- NULL # R CMD check
166167
is <- pull(ij, id_y) # elements in i
167168
js <- pull(ij, id_x) # masks in j
168169
na <- setdiff(seq_len(nrow(i)), is)

‎R/methods.R‎

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
#' @importFrom utils .DollarNames
21
#' @export
2+
#' @importFrom utils .DollarNames
33
.DollarNames.SpatialData <- \(x, pattern="") grep(pattern, .LAYERS, value=TRUE)
44

5-
#' @rdname SpatialData
65
#' @exportMethod $
6+
#' @rdname SpatialData
77
setMethod("$", "SpatialData", \(x, name) attr(x, name))
88

9+
#' @export
910
#' @rdname SpatialData
1011
#' @importFrom methods callNextMethod
11-
#' @export
1212
setMethod("[[", c("SpatialData", "numeric"), \(x, i, ...) {
1313
i <- .LAYERS[i]
1414
callNextMethod(x, i)
@@ -144,12 +144,24 @@ setMethod("element", c("SpatialData", "ANY"), \(x, i)
144144

145145
# get all ----
146146

147-
#' @name SpatialData
148-
#' @exportMethod images labels points shapes tables
147+
#' @export
148+
#' @rdname SpatialData
149149
setMethod("images", "SpatialData", \(x) x$images)
150+
151+
#' @export
152+
#' @rdname SpatialData
150153
setMethod("labels", "SpatialData", \(x) x$labels)
154+
155+
#' @export
156+
#' @rdname SpatialData
151157
setMethod("points", "SpatialData", \(x) x$points)
158+
159+
#' @export
160+
#' @rdname SpatialData
152161
setMethod("shapes", "SpatialData", \(x) x$shapes)
162+
163+
#' @export
164+
#' @rdname SpatialData
153165
setMethod("tables", "SpatialData", \(x) x$tables)
154166

155167
# get nms ----

‎R/read.R‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@
1212
#' Control which elements should be read for each layer.
1313
#' The default, NULL, reads all elements; alternatively, may be FALSE
1414
#' to skip a layer, or a integer vector specifying which elements to read.
15-
#' @param anndataR logical specifying whether
16-
#' to use \code{anndataR} to read tables;
17-
#' defaults to FALSE in `readSpatialData`, and `readTable`,
18-
#' so that pythonic \code{anndata} are used.
1915
#' @param ... option arguments passed to and from other methods.
2016
#'
2117
#' @return
@@ -146,6 +142,7 @@ readSpatialData <- function(x,
146142
lapply(j, \(.) do.call(f, list(.)))
147143
}
148144

149-
sd <- lapply(setNames(nm=.LAYERS[!skip]), .readLayer)
145+
names(ls) <- ls <- .LAYERS[!skip]
146+
sd <- lapply(ls, .readLayer)
150147
do.call(SpatialData, sd)
151148
}

0 commit comments

Comments
 (0)