From 37924be8beb2b918b304d8705dea6b2ab11e5b08 Mon Sep 17 00:00:00 2001 From: rhijmans Date: Wed, 21 Jun 2023 12:20:18 -0700 Subject: [PATCH] w --- R/ncdf.R | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/R/ncdf.R b/R/ncdf.R index fb12b5675..58047953a 100644 --- a/R/ncdf.R +++ b/R/ncdf.R @@ -217,6 +217,11 @@ setMethod("writeCDF", signature(x="SpatRaster"), function(x, filename, varname, longname="", unit="", split=FALSE, ...) { filename <- trimws(filename) + if (length(filename) > 1) { + if (length(filename) != nlyr(x)) { + stop("either provide a single filename, or the same number as nlyr(x)") + } + } stopifnot(filename != "") if (split) { y <- sds(as.list(x))