diff --git a/R/CST_SaveExp.R b/R/CST_SaveExp.R index 1c419be56453ef5e9515cd4a0b7130a4b0826ec4..d6e98f384cde4dad9e41d48e88a9d754c609594c 100644 --- a/R/CST_SaveExp.R +++ b/R/CST_SaveExp.R @@ -325,8 +325,7 @@ SaveExp <- function(data, destination = "./", Dates = NULL, coords = NULL, # Spatial coordinates if (!any(dimnames %in% .KnownLonNames()) | !any(dimnames %in% .KnownLatNames())) { - warning("Spatial coordinate names do not match any of the names accepted by ", - "the package.") + warning("Spatial coordinates not found.") lon_dim <- NULL lat_dim <- NULL } else { @@ -438,12 +437,17 @@ SaveExp <- function(data, destination = "./", Dates = NULL, coords = NULL, all(nchar(startdates) != 8) & all(nchar(startdates) != 6)))) { warning("Parameter 'startdates' should be a character string containing ", "the start dates in the format 'yyyy-mm-dd', 'yyyymmdd', 'yyyymm', ", - "'POSIXct' or 'Dates' class.") + "'POSIXct' or 'Dates' class. Files will be named with Dates instead.") startdates <- Subset(Dates, along = ftime_dim, 1, drop = 'selected') + if (!is.null(format(startdates, "%Y%m%d"))) { + startdates <- format(startdates, "%Y%m%d") + } } + } else if (all(dim(Dates)[!names(dim(Dates)) %in% c(ftime_dim, sdate_dim)] == 1)) { + dim(Dates) <- dim(Dates)[names(dim(Dates)) %in% c(ftime_dim, sdate_dim)] } else { stop("Parameter 'Dates' must have start date dimension and ", - "forecast time dimension.") + "forecast time dimension.") } } # startdates @@ -487,7 +491,7 @@ SaveExp <- function(data, destination = "./", Dates = NULL, coords = NULL, alldims <- c(dat_dim, var_dim, sdate_dim, lon_dim, lat_dim, memb_dim, ftime_dim) if (!all(dimnames %in% alldims)) { unknown_dims <- dimnames[which(!dimnames %in% alldims)] - warning("Detected unknown dimension: ", paste(unknown_dims, collapse = ', ')) + # warning("Detected unknown dimension: ", paste(unknown_dims, collapse = ', ')) memb_dim <- c(memb_dim, unknown_dims) alldims <- c(dat_dim, var_dim, sdate_dim, lon_dim, lat_dim, memb_dim, ftime_dim) } diff --git a/tests/testthat/test-CST_SaveExp.R b/tests/testthat/test-CST_SaveExp.R index cb028d6a42ad8803cf8bce745ad1ae8cd7eb1cf1..a05c5bd64d8b4d16b0130d8c5ccf06ec0ded4a86 100644 --- a/tests/testthat/test-CST_SaveExp.R +++ b/tests/testthat/test-CST_SaveExp.R @@ -132,11 +132,6 @@ test_that("1. Input checks: CST_SaveExp", { "as NULL if there is no member dimension.") ) ) - # expect_warning( - # CST_SaveExp(data = cube2, memb_dim = c('member', 'ensemble'), - # ftime_dim = 'ftime', dat_dim = NULL, var_dim = NULL), - # paste0("Detected unknown dimension: test, test2") - # ) }) ############################################## @@ -201,9 +196,7 @@ test_that("1. Input checks", { # dat_dim = NULL, var_dim = NULL, single_file = TRUE), # "Parameter 'varname' is NULL. It will be assigned to 'X'.", # "Parameter 'metadata' is not provided so the metadata saved will be incomplete.", - # paste0("Spatial coordinate names do not match any of the names accepted by ", - # "the package."), - # "Detected unknown dimension: test" + # paste0("Spatial coordinates not found.") # ) expect_error( SaveExp(data = dat1, varname = 1, ftime_dim = NULL, sdate_dim = NULL,