From 34cf591163979f02fa8b0d269f7f19496e5b7e2e Mon Sep 17 00:00:00 2001 From: "MAHOUDI Abdallah (Externe)" Date: Mon, 4 Mar 2024 17:26:30 +0100 Subject: [PATCH] change stop by warning and return same data table in local and API mode --- R/readClusterDesc.R | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/R/readClusterDesc.R b/R/readClusterDesc.R index 4f0e9195..15bc4039 100644 --- a/R/readClusterDesc.R +++ b/R/readClusterDesc.R @@ -107,6 +107,12 @@ readClusterSTDesc <- function(opts = simOptions()) { path <- file.path(opts$inputPath, dir) + columns = c("group","enabled","must_run","unit_count","nominal_capacity", + "min_stable_power","spinning","min_up_time","min_down_time", + "co2","marginal_cost","fixed_cost","startup_cost","market_bid_cost", + "spread_cost","ts_gen","volatility_forced","volatility_planned", + "law_forced","law_planned") + if(opts$typeLoad == 'api'){ jsoncld <- read_secure_json(paste0(path, "&depth=4"), token = opts$token, timeout = opts$timeout, config = opts$httr_config) res <- rbindlist(mapply(function(X1, Y1){ @@ -123,9 +129,11 @@ readClusterSTDesc <- function(opts = simOptions()) { clusters[, .SD, .SDcols = order(names(clusters))] },jsoncld, names(jsoncld), SIMPLIFY = FALSE), fill = TRUE) - if(length(res) == 0) - stop("Cannot find cluster description.", call. = FALSE) - + if(length(res) == 0){ + warning("No cluster description available.", call. = FALSE) + res <- setNames(data.table(matrix(nrow = 0, ncol = 22)), c("area", "cluster", columns)) + } + res <- res[, .SD, .SDcols = c("area", "name", "group", names(res)[!names(res) %in%c("area", "name", "group")])] }else{ @@ -146,7 +154,10 @@ readClusterSTDesc <- function(opts = simOptions()) { } - if(length(res) == 0) stop("Cannot find cluster description.", call. = FALSE) + if(length(res) == 0){ + warning("No cluster description available.", call. = FALSE) + res <- setNames(data.table(matrix(nrow = 0, ncol = 22)), c("area", "cluster", columns)) + } res <- as.data.table(res) setnames(res, "name", "cluster")