From cf32fed7157cfc516a0dd331a52f47b77c568f88 Mon Sep 17 00:00:00 2001 From: rhijmans Date: Thu, 14 Nov 2024 06:21:01 -0800 Subject: [PATCH] fixes #1640 --- R/replace_values.R | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/R/replace_values.R b/R/replace_values.R index bbe0954db..f151a7636 100644 --- a/R/replace_values.R +++ b/R/replace_values.R @@ -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") @@ -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) {