Skip to content

Commit

Permalink
Terra update problems and get rid of warning from cropping
Browse files Browse the repository at this point in the history
  • Loading branch information
lambdamoses committed Jan 21, 2025
1 parent 2169a8b commit edab6fd
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
3 changes: 2 additions & 1 deletion R/coerce.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@
terra::RGB(im_new) <- seq_len(3)
} else if (inherits(img, "RemoteSpatialImage") || inherits(img, "StoredSpatialImage")) {
suppressWarnings(im_new <- rast(imgSource(img)))
if (packageVersion('terra') == as.package_version("1.7.83"))
if (packageVersion('terra') == as.package_version("1.7.83") ||
packageVersion('terra') == as.package_version("1.8.10"))
im_new <- terra::flip(im_new)
} else {
warning("Don't know how to convert image ", i, " to SpatRaster, ",
Expand Down
1 change: 1 addition & 0 deletions R/geometry_operation.R
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,7 @@ crop <- function(x, y = NULL, colGeometryName = 1L, sample_id = "all",
" was/were removed by the cropping."
)
}
samples_use <- intersect(samples_use, sampleIDs(out))
if (!"col" %in% keep_whole) {
# colGeometries should have already been subsetted here
# Also actually crop all geometries for the samples of interest.
Expand Down
9 changes: 6 additions & 3 deletions R/read.R
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ read10xVisiumSFE <- function(samples = "",
data <- match.arg(data)
unit <- match.arg(unit)
flip <- match.arg(flip)
if (packageVersion('terra') == as.package_version("1.7.83"))
if (packageVersion('terra') == as.package_version("1.7.83") ||
packageVersion('terra') == as.package_version("1.8.10"))
flip <- "none"
if (is_present(load)) {
deprecate_warn("1.8.0", "read10xVisiumSFE(load)")
Expand Down Expand Up @@ -326,7 +327,8 @@ readVisiumHD <- function(data_dir, bin_size = c(2L, 8L, 16L),
data <- match.arg(data)
unit <- match.arg(unit)
flip <- match.arg(flip)
if (packageVersion('terra') == as.package_version("1.7.83"))
if (packageVersion('terra') == as.package_version("1.7.83") ||
packageVersion('terra') == as.package_version("1.8.10"))
flip <- "none"
images <- match.arg(images, several.ok = TRUE)
bin_size <- match.arg(as.character(bin_size), choices = c("2", "8", "16"),
Expand Down Expand Up @@ -747,7 +749,8 @@ readVizgen <- function(data_dir,
check_installed("sfarrow")
data_dir <- normalizePath(data_dir, mustWork = TRUE)
flip <- match.arg(flip)
if (packageVersion('terra') == as.package_version("1.7.83"))
if (packageVersion('terra') == as.package_version("1.7.83") ||
packageVersion('terra') == as.package_version("1.8.10"))
flip <- "none"
image <- match.arg(image, several.ok = TRUE)
if ((any(z < 0) || any(z > 6)) && z != "all") {
Expand Down
6 changes: 4 additions & 2 deletions tests/testthat/test-image.R
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,8 @@ test_that("mirrorImg, SpatRasterImage method", {
img_m2 <- mirrorImg(img, maxcell = 100)
expect_equal(dim(img_m2), c(13,8,3))
# check content
if (packageVersion('terra') == as.package_version("1.7.83"))
if (packageVersion('terra') == as.package_version("1.7.83") ||
packageVersion('terra') == as.package_version("1.8.10"))
expect_equal(imgRaster(img_m2)[4,3,2][[1]], 190)

# Use filename
Expand Down Expand Up @@ -243,7 +244,8 @@ test_that("scaleImg, SpatRasterImage method, EBI behind the scene", {

test_that("affineImg, SpatRasterImage method, EBI behind the scene", {
suppressWarnings(spi <- SpatRasterImage(rast(img_path)))
if (packageVersion('terra') == as.package_version("1.7.83"))
if (packageVersion('terra') == as.package_version("1.7.83") ||
packageVersion('terra') == as.package_version("1.8.10"))
spi <- mirrorImg(spi, "vertical")
# Should rotate clockwise somewhat, squished to be flatter, shear to the right
M <- matrix(c(0.6, -0.2, 0.2, 0.3), nrow = 2)
Expand Down

0 comments on commit edab6fd

Please sign in to comment.