From 07c792cb3bc953afc16ad6c031601a3481056ddf Mon Sep 17 00:00:00 2001 From: rhijmans Date: Mon, 8 Jul 2024 07:59:07 -0700 Subject: [PATCH] fixes #336 --- R/coerce.R | 3 +++ 1 file changed, 3 insertions(+) diff --git a/R/coerce.R b/R/coerce.R index d72724d3..d610411e 100644 --- a/R/coerce.R +++ b/R/coerce.R @@ -30,6 +30,9 @@ setAs("SpatRaster", "Raster", if ((length(usid) == 1) & (b$source[1] != "")) { if ((nl == nrow(b)) && (b$bands[1] == 1) && (all(diff(b$bands) == 1))) { r <- raster::brick(b$source[1]) + if (nlayers(r) != nl) { + r <- r[[b$bands]] + } } else { r <- raster::stack(b$source[1], bands=b$bands) }