diff --git a/NAMESPACE b/NAMESPACE index deb945ef..1dca5501 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -104,6 +104,7 @@ importFrom(plyr,llply) importFrom(purrr,quietly) importFrom(shiny,getDefaultReactiveDomain) importFrom(shiny,incProgress) +importFrom(shiny,isRunning) importFrom(shiny,withProgress) importFrom(stats,as.formula) importFrom(stats,setNames) diff --git a/NEWS.md b/NEWS.md index dcf848b0..1db4edae 100644 --- a/NEWS.md +++ b/NEWS.md @@ -12,7 +12,7 @@ NEW FEATURES: It contains a table with group dimensions of time series for binding constraints. * `readAntares()` new parameter **clustersST** to read (output simulation) short-term clusters * New function `readAntaresSTClusters()` - +* `fread_antares()` shiny compatible with a conditional processing of the error messages BREAKING CHANGES : @@ -25,6 +25,7 @@ BUGFIXES : * `readInputThermal()` return data from file data.txt with `thermalData` parameter * `setSimulationPath()` has also the parameter **areasWithSTClusters** in 'output' mode * `setSimulationPathAPI()`: control the existence of the output folder **links** or **areas** before reading the data (upgrade Antares Web) +* `readClusterDesc()` / `readClusterResDesc()` / `readClusterSTDesc()` return a data.table in API mode # antaresRead 2.7.0 diff --git a/R/readClusterDesc.R b/R/readClusterDesc.R index f9f75032..23b4fb2d 100644 --- a/R/readClusterDesc.R +++ b/R/readClusterDesc.R @@ -104,18 +104,17 @@ readClusterSTDesc <- function(opts = simOptions()) { "st-storage/clusters" = "st-storages" ) - if(api_study){ - + if (api_study) { # api request with all columns - list_clusters = api_get( + list_clusters <- api_get( opts = opts, endpoint = paste0(opts$study_id, "/table-mode/", table_type), - query = list( - columns = "" - ) + query = list(columns = "") ) - return(list_clusters) + dt_clusters <- .convert_list_clusterDesc_to_datatable(list_clusters) + + return(dt_clusters) } # "text" mode @@ -124,7 +123,7 @@ readClusterSTDesc <- function(opts = simOptions()) { # READ cluster properties properties <- get_input_cluster_properties(table_type = table_type, opts = opts) - + # read properties for each area res <- plyr::llply(areas, function(x, prop_ref=properties) { clusters <- readIniFile(file.path(path, x, "list.ini")) @@ -225,3 +224,29 @@ get_input_cluster_properties <- function(table_type, opts){ return(wide_ref) } + + +.convert_list_clusterDesc_to_datatable <- function(list_clusters) { + + if (length(list_clusters) == 0) { + return(data.table()) + } + + rows_cluster <- lapply(names(list_clusters), FUN = function(cl_name) { + + row_cluster <- as.data.frame(list_clusters[[cl_name]]) + row_cluster[,c("area", "cluster")] <- unlist(strsplit(cl_name, split = " / ")) + + return(row_cluster) + } + ) + + df_clusters <- do.call("rbind", rows_cluster) + id_cols <- intersect(c("area", "cluster", "group"), colnames(df_clusters)) + additional_cols <- setdiff(colnames(df_clusters), id_cols) + df_clusters <- df_clusters[,c(id_cols, additional_cols)] + df_clusters$cluster <- as.factor(tolower(df_clusters$cluster)) + colnames(df_clusters) <- tolower(colnames(df_clusters)) + + return(as.data.table(df_clusters)) +} diff --git a/R/utils_api.R b/R/utils_api.R index 499c7d27..370ba422 100644 --- a/R/utils_api.R +++ b/R/utils_api.R @@ -1,4 +1,5 @@ #' @importFrom utils URLencode +#' @importFrom shiny isRunning fread_antares <- function(opts, file, ...) { if (identical(opts$typeLoad, "api")) { file <- gsub("\\.txt$", "", file) @@ -9,7 +10,10 @@ fread_antares <- function(opts, file, ...) { ) suppressWarnings( tryCatch(fread(response, ...), error = function(e){ - message(file); message(e) + if(isRunning()) + e <- as.character(e) + message(file) + message(e) })) } else { suppressWarnings(