Skip to content

Commit

Permalink
fixes #1236
Browse files Browse the repository at this point in the history
  • Loading branch information
see24 committed Jul 17, 2023
1 parent 8b4cc83 commit 2af3639
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
4 changes: 3 additions & 1 deletion R/values.R
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,9 @@ setMethod("all.equal", signature(target="SpatRaster", current="SpatRaster"),
hvC <- hasValues(current)
if (hvT && hvC) {
s <- spatSample(c(target, current), maxcell, "regular")
a <- all.equal(s[,1], s[,2], ...)
s1 <- unlist(s[,1:nlyr(target)], use.names = FALSE)
s2 <- unlist(s[,(nlyr(target)+1):(nlyr(target) +nlyr(current))], use.names = FALSE)
a <- all.equal(s1, s2, ...)
} else if (hvT || hvC) {
if (hvT) {
a <- "target has cell values, current does not"
Expand Down
16 changes: 16 additions & 0 deletions inst/tinytest/test_equal.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

x <- sqrt(1:100)
mat <- matrix(x, 10, 10)
r1 <- rast(nrows=10, ncols=10, xmin=0, vals = x)
r2 <- rast(nrows=10, ncols=10, xmin=0, vals = mat)

expect_inherits(all.equal(r1, r2), "character")

expect_true(all.equal(r1, r1))

# works for multiple layers
r3 <- c(r1, r2)
r4 <- c(r1, r2)

expect_true(all.equal(r3, r4))

0 comments on commit 2af3639

Please sign in to comment.