Skip to content
Open
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
3 changes: 1 addition & 2 deletions R/combine.R
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ setMethod("combine", c("list", "missing"), \(x, y, ...) {
# get current element names
old <- lapply(x, \(z) unlist(colnames(z)))
# get list names; if missing, use empty strings
if (is.null(nms <- names(x)))
nms <- character(length(x))
nms <- names(x) %||% character(length(x))
# prepend list names to element names where available
new <- lapply(seq_along(x), \(i) {
if (nms[i] == "") return(old[[i]])
Expand Down
10 changes: 0 additions & 10 deletions R/crop.R
Original file line number Diff line number Diff line change
Expand Up @@ -109,16 +109,6 @@ NULL
# get transformation for space 'j'
j <- .val_id(j, CTname(x))
ct <- CTlist(x)[[j]]
# helper to adapt transformation data to spatial (XY) dims
axs <- axes(x)
nms <- vapply(axs, \(.) .$name, character(1))
ix <- match("x", nms)
iy <- match("y", nms)
if (is.na(ix) || is.na(iy)) {
# default to last two (YX)
n <- length(nms)
ix <- n; iy <- n-1
}
ax <- .get_xy_axes(x)
.adapt <- \(t, type) {
if (is.null(t)) return(NULL)
Expand Down
3 changes: 2 additions & 1 deletion R/sdArray.R
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ setMethod("data_type", "DelayedArray", \(x) {
if (is.null(v)) return()
if (v == "0.5") x <- x$ome
# NOTE: can't use 'vapply' as we
# have encountered integer 'label's
# have encountered integer 'label's
# Tracked in https://github.com/scverse/spatialdata/issues/1136
x <- x$omero$channels
x$label %||% unlist(lapply(x, `[[`, "label"))
}
Expand Down
9 changes: 3 additions & 6 deletions R/sdAttrs.R
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,7 @@ setMethod("regions", "SingleCellExperiment", \(x) {
#' @importFrom SingleCellExperiment int_metadata<-
setReplaceMethod("region", c("SingleCellExperiment", "character"), \(x, value) {
stopifnot(all(nchar(value) > 0, na.rm=TRUE))
if (is.null(rk <- region_key(x)))
rk <- region_key(x) <- "region"
rk <- region_key(x) <- region_key(x) %||% "region"
int_metadata(x)$spatialdata_attrs[[rk]] <- sort(unique(value))
return(x)
})
Expand All @@ -237,7 +236,7 @@ setReplaceMethod("region", c("SingleCellExperiment", "NULL"), \(x, value) {
setReplaceMethod("regions", c("SingleCellExperiment", "character"), \(x, value) {
stopifnot(length(value) %in% c(1, ncol(x)))
stopifnot(all(nchar(value) > 0, na.rm=TRUE))
if (is.null(rk <- region_key(x))) region_key(x) <- "region"
rk <- region_key(x) <- region_key(x) %||% "region"
Comment thread
Bisaloo marked this conversation as resolved.
int_metadata(x)$spatialdata_attrs[[rk]] <- sort(unique(value))
int_colData(x)[[rk]] <- value
return(x)
Expand Down Expand Up @@ -314,9 +313,7 @@ setMethod("instances", "SingleCellExperiment", \(x) {
#' @rdname SpatialDataAttrs
#' @importFrom SingleCellExperiment int_colData<-
setReplaceMethod("instances", c("SingleCellExperiment", "ANY"), \(x, value) {
ik <- instance_key(x)
if (is.null(ik))
ik <- "instance_id"
ik <- instance_key(x) %||% "instance_id"
int_colData(x)[[ik]] <- value
Comment thread
HelenaLC marked this conversation as resolved.
return(x)
})
5 changes: 2 additions & 3 deletions R/sdFrame.R
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ NULL
#' @importFrom sf st_sf st_sfc st_as_sf st_point st_polygon
.df_to_sf <- \(data, type=c("POINT", "POLYGON")) {
type <- match.arg(type)
if (is.null(data) || isTRUE(nrow(data) == 0)) {
if (isTRUE(NROW(data) == 0)) {
# return empty data.frame with geometry column
fn <- switch(type, POINT=st_point, st_polygon)
return(st_sf(geometry=st_sfc(fn())[0], crs=NA))
Expand Down Expand Up @@ -134,8 +134,7 @@ SpatialDataPoint <- \(data=NULL, meta=SpatialDataAttrs(type="frame"), metadata=l
if (!is(data, "duckspatial_df"))
data <- .duck(data, "sdPoint")
za <- as.list(meta)
if (is.null(za$spatialdata_attrs))
za$spatialdata_attrs <- list()
za$spatialdata_attrs <- za$spatialdata_attrs %||% list()
if (!is.null(ik)) {
stopifnot(ik %in% colnames(data))
instance_key(za) <- ik
Expand Down
4 changes: 2 additions & 2 deletions R/tables.R
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,8 @@ setMethod("setTable", c("SpatialData", "character"), \(x, i, y,
if (!. %in% c("labels", "shapes"))
stop("can't add 'table' for", .)

if (is.null(region_key(y))) region_key(y) <- rk
if (is.null(instance_key(y))) instance_key(y) <- ik
region_key(y) <- region_key(y) %||% rk
instance_key(y) <- instance_key(y) %||% ik

if (is.null(region(y))) {
regions(y) <- i
Expand Down