Skip to content

Commit

Permalink
fixes #1640
Browse files Browse the repository at this point in the history
  • Loading branch information
rhijmans committed Nov 14, 2024
1 parent 4b3d9b9 commit cf32fed
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion R/replace_values.R
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,11 @@ setReplaceMethod("[", c("SpatRaster", "ANY", "ANY", "ANY"),
function(x, i, j, k, value) {

m <- c(missing(i), missing(j), missing(k))
if (all(m) && is.matrix(value) && ((nrow(value) == nrow(x)) && (ncol(value) == ncol(x) * nlyr(x)))) {
values(x) <- value
return(x)
}

s <- rep(FALSE, 3)
if (!m[1]) s[1] <- inherits(i, "list")
if (!m[2]) s[2] <- inherits(j, "list")
Expand All @@ -276,7 +281,7 @@ setReplaceMethod("[", c("SpatRaster", "ANY", "ANY", "ANY"),
m[3] <- TRUE
}

if ((!m[1]) && (inherits(i, "matrix"))) {
if ((!m[1]) && (inherits(i, "matrix"))) {
if (ncol(i) == 1) {
i <- i[,1]
} else if (ncol(i) == 2) {
Expand Down

0 comments on commit cf32fed

Please sign in to comment.