Skip to content
Closed
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: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Suggests:
EBImage,
knitr,
Rgraphviz,
testthat
testthat (>= 3.0.0)
biocViews:
DataImport,
DataRepresentation,
Expand All @@ -67,3 +67,4 @@ VignetteBuilder: knitr
BugReports: https://github.com/HelenaLC/spatialdataR/issues
URL: https://helenalc.github.io/spatialdataR, https://github.com/HelenaLC/spatialdataR
Config/roxygen2/version: 8.0.0
Config/testthat/edition: 3
2 changes: 1 addition & 1 deletion R/methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ f <- \(e) setReplaceMethod(e,
\(x, i, ..., value) {
nms <- get(paste0(e, "Names"))(x)
n <- length(get(paste0(e, "s"))(x))
i <- ifelse(i > n, paste0(e, n+1), nms[i])
i <- if(i > n) paste0(e, n+1) else nms[i]
set <- get(paste0(e, "<-"))
set(x, i, value=value)
})
Expand Down
12 changes: 6 additions & 6 deletions R/misc.R
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ NULL
cat(sprintf(" - %s (%s)\n", p, d), sep="")
# shapes
nc <- vapply(shapes(object), ncol, numeric(1))
geom <- ifelse(nc == 1, "polygon", "circle")
geom <- c("circle", "polygon")[as.integer(nc == 1) + 1L]
d <- vapply(shapes(object), nrow, numeric(1))
d <- paste(d, unname(geom), sep=",")
cat(sprintf("- shapes(%s):\n", length(s)))
Expand Down Expand Up @@ -89,7 +89,7 @@ setMethod("show", "SpatialData", .showSpatialData)
#' @importFrom S4Vectors coolcat
.showArray <- function(object) {
n.object <- length(object@data)
cat("class: ", class(object), ifelse(n.object > 1, "(MultiScale)", ""),"\n")
cat("class: ", class(object), if (n.object > 1) "(MultiScale)" else "", "\n")
scales <- vapply(object@data, \(x) paste0(dim(x), collapse=","), character(1))
coolcat("Scales (%d): (%s)", scales)
}
Expand Down Expand Up @@ -132,12 +132,12 @@ setMethod("show", "SpatialDataShape", .showShape)
# coordinate transformations
CTshow <- \(l) {
f <- \(.) {
. <- paste(unlist(.), collapse=",")
ifelse(grepl(",", .), sprintf("[%s]", .), .)
if (length(.) > 1).

@HelenaLC HelenaLC Aug 15, 2026

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this dot after the parentheses-- typo? Shouldn't it be if-else here too?

@Bisaloo Bisaloo Aug 15, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you made it work in #246. Correct? If so, let's close this one.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I believe so. Sorry I was confused earlier.

sprintf("[%s]", paste(unlist(.), collapse=","))
}
g <- \(.) {
na <- is.null(.) || !length(unlist(.))
ifelse(na, "", paste0(":", f(lapply(., f))))
na <- !length(unlist(.))
if (na) "" else paste0(":", f(lapply(., f)))
}
h <- \(.) sprintf("(%s%s)", .$type, g(.[[.$type]]))
if (l$type == "sequence") {
Expand Down
2 changes: 2 additions & 0 deletions tests/testthat.R
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
library(testthat)
library(spatialdataR)

test_check("spatialdataR")
28 changes: 28 additions & 0 deletions tests/testthat/_snaps/methods.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# show

Code
show(x)
Output
class: SpatialData
- images(2):
- blobs_image (3,64,64)
- blobs_multiscale_image (3,64,64)
- labels(2):
- blobs_labels (64,64)
- blobs_multiscale_labels (64,64)
- points(1):
- blobs_points (200)
- shapes(3):
- blobs_circles (5,circle)
- blobs_multipolygons (2,polygon)
- blobs_polygons (5,polygon)
- tables(1):
- table (3,10) [blobs_labels]
coordinate systems(5):
- global(8): blobs_image blobs_multiscale_image ... blobs_polygons
blobs_points
- scale(1): blobs_labels
- translation(1): blobs_labels
- affine(1): blobs_labels
- sequence(1): blobs_labels

5 changes: 5 additions & 0 deletions tests/testthat/test-methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -329,3 +329,8 @@ test_that("[,SpatialData", {
# infinite 'j'
expect_no_error(y <- x[1, Inf])
})

# show ----
test_that("show", {
expect_snapshot(show(x))
})
Loading