diff --git a/NEWS.md b/NEWS.md index d9d015b0..2e4d9013 100644 --- a/NEWS.md +++ b/NEWS.md @@ -8,7 +8,8 @@ NEW FEATURES : ### Breaking changes * `setPlaylist()` optimized for the API mode - - returned an updated list of simulation parameters returned by the function `setSimulationPath()` and `setSimulationPathAPI()` + - returned an updated list of simulation parameters returned by the function `setSimulationPath()` and `setSimulationPathAPI()`. +* `createCluster()` parameter `list_pollutants` default value to NULL. * `createBindingConstraint()` parameter `coefficients` must be alphabetically ordered. BUGFIXES : @@ -17,7 +18,7 @@ BUGFIXES : * Fix `setPlaylist()` works in API and local mode with weights. * Fix `getPlaylist()` works in API and local mode with weights. * Fix `createDSR()` in API mode : daily binding constraint takes 366 rows. -* Fix `createCluster()` parameter `list_pollutants` stop for Antares Version < 860. +* Fix `createCluster()` and `editCluster()` parameter `list_pollutants` stop if Antares Version < 8.6.0 * `getJobs()` no longer returns duplicates and displays the two new columns `owner_id` and `owner_name`. # antaresEditObject 0.6.1 diff --git a/R/createCluster.R b/R/createCluster.R index 3f043bee..3addfa51 100644 --- a/R/createCluster.R +++ b/R/createCluster.R @@ -156,7 +156,7 @@ createCluster <- function(area, cluster_name, group = "Other", ..., - list_pollutants = list_pollutants_values(), + list_pollutants = NULL, time_series = NULL, prepro_data = NULL, prepro_modulation = NULL, @@ -166,28 +166,24 @@ createCluster <- function(area, # check study parameters assertthat::assert_that(inherits(opts, "simOptions")) - # static name of list parameters of pulluants + # static name of list parameters of pollutants name_list_param_poll <- names(list_pollutants_values()) # check v860 - # check list pulluants parameters + # check list pollutants parameters if(opts$antaresVersion >= 860){ - if(!is.null(list_pollutants) & !assert_that(inherits(list_pollutants, "list"))) + if(!is.null(list_pollutants) & !(class(list_pollutants) == "list")) stop("Parameter 'list_pollutants' must be a 'list'") if(!all(names(list_pollutants) %in% name_list_param_poll)) stop(append("Parameter 'list_pollutants' must be named with the following elements: ", paste0(name_list_param_poll, collapse= ", "))) - - # check if all elements are NULL => replace by NULL - # API (only) can't create with NULL values - all_null <- lapply(list_pollutants, is.null) - all_null <- all(unlist(all_null)) - - if(all_null) - list_pollutants <- NULL } - + else{ + if(!is.null(list_pollutants)) + stop("antaresVersion should be >= v8.6.0 to use parameter 'list_pollutants'.") + } + # statics groups thermal_group <- c("Gas", diff --git a/R/editCluster.R b/R/editCluster.R index 94c96fbe..5dccd7e4 100644 --- a/R/editCluster.R +++ b/R/editCluster.R @@ -109,9 +109,13 @@ editClusterRES <- function(area, cluster_name <- paste(area, cluster_name, sep = "_") # v860 pollutants - if(opts$antaresVersion >= 860) + if(opts$antaresVersion >= 860){ params_cluster <- append(params_cluster, list_pollutants) - + } + else{ + if(!is.null(list_pollutants)) + stop("antaresVersion should be >= v8.6.0 to use parameter 'list_pollutants'.") + } # Handle case sensitivity in name of clusters API clusters <- names(readIni(file.path("input", cluster_type, "clusters", area, "list"), opts= opts)) diff --git a/man/createCluster.Rd b/man/createCluster.Rd index 4e1e5d0e..522a788e 100644 --- a/man/createCluster.Rd +++ b/man/createCluster.Rd @@ -10,7 +10,7 @@ createCluster( cluster_name, group = "Other", ..., - list_pollutants = list_pollutants_values(), + list_pollutants = NULL, time_series = NULL, prepro_data = NULL, prepro_modulation = NULL, diff --git a/tests/testthat/test-createCluster.R b/tests/testthat/test-createCluster.R index 68f5ea41..db7d415c 100644 --- a/tests/testthat/test-createCluster.R +++ b/tests/testthat/test-createCluster.R @@ -109,6 +109,16 @@ test_that("Create cluster with pollutants params (new feature v8.6)",{ testthat::expect_equal(all(is.na(values_default)), TRUE) }) + bad_pollutants_param <- "not_a_list" + testthat::expect_error(createCluster( + area = getAreas()[1], + cluster_name = "bad_cluster", + group = "Other", + unitcount = as.integer(1), + nominalcapacity = 100, + list_pollutants = bad_pollutants_param, + opts = opts_test), regexp = "'list_pollutants' must be a 'list'") + pollutants_params <- list( "nh3"= 0.25, "nox"= 0.45, "pm2_5"= 0.25, "pm5"= 0.25, "pm10"= 0.25, "nmvoc"= 0.25, "so2"= 0.25, diff --git a/tests/testthat/test-editCluster.R b/tests/testthat/test-editCluster.R index a5f6a8b7..9dd8112e 100644 --- a/tests/testthat/test-editCluster.R +++ b/tests/testthat/test-editCluster.R @@ -58,6 +58,16 @@ opts_test <- antaresRead::setSimulationPath(study_temp_path, "input") test_that("Edit cluster with pollutants params (new feature v8.6)",{ + bad_pollutants_param <- "not_a_list" + testthat::expect_error(createCluster( + area = getAreas()[1], + cluster_name = "mycluster_pollutant", + group = "Other", + unitcount = as.integer(1), + nominalcapacity = 100, + list_pollutants = bad_pollutants_param, + opts = opts_test), regexp = "'list_pollutants' must be a 'list'") + pollutants_params <- list( "nh3"= 0.25, "nox"= 0.45, "pm2_5"= 0.25, "pm5"= 0.25, "pm10"= 0.25, "nmvoc"= 0.25, "so2"= 0.25,