Search code examples
rterra

Why does writeRaster in terra give a warning message?


I am trying to rasters by layer using terra package. I am using the following code

library(terra)

# first create a raster
r1 <- r2 <- r3 <- rast(nrow=10, ncol=10)
# Assign random cell values
values(r1) <- runif(ncell(r1))
values(r2) <- runif(ncell(r2))
values(r3) <- runif(ncell(r3))
s <- c(r1, r2, r3)

names(s) <- c("a", "b", "c")

writeRaster(s, paste0(names(s), ".tif"), overwrite=TRUE)

It works with the following warning message

Warning message:
In tools::file_ext(filename) %in% c("nc", "cdf") || isTRUE(list(...)$filetype ==  :
  'length(x) = 3 > 1' in coercion to 'logical(1)'

What does this message means?


Solution

  • That is a bug that you can ignore. It was fixed in the development version that you can install with install.packages('terra', repos='https://rspatial.r-universe.dev') but it has not made it to CRAN yet.