diff --git a/R/createCluster.R b/R/createCluster.R index 3f043bee..a2061f2d 100644 --- a/R/createCluster.R +++ b/R/createCluster.R @@ -266,7 +266,7 @@ createClusterRES <- function(area, ) } - +#' @importFrom data.table fwrite .createCluster <- function(area, cluster_name, ..., @@ -301,6 +301,7 @@ createClusterRES <- function(area, if (add_prefix) cluster_name <- paste(area, cluster_name, sep = "_") params_cluster$name <- cluster_name + lower_cluster_name <- tolower(cluster_name) # v860 pollutants if(opts$antaresVersion >= 860) @@ -338,7 +339,7 @@ createClusterRES <- function(area, currPath <- ifelse(identical(cluster_type, "renewables"), "input/renewables/series/%s/%s/series", "input/thermal/series/%s/%s/series") cmd <- api_command_generate( action = "replace_matrix", - target = sprintf(currPath, area, tolower(cluster_name)), + target = sprintf(currPath, area, lower_cluster_name), matrix = time_series ) api_command_register(cmd, opts = opts) @@ -359,15 +360,15 @@ createClusterRES <- function(area, # params_cluster <- stats::setNames(object = list(params_cluster), nm = cluster_name) # path to ini file containing clusters' name and parameters - path_clusters_ini <- file.path(inputPath, cluster_type, "clusters", tolower(area), "list.ini") + path_clusters_ini <- file.path(inputPath, cluster_type, "clusters", area, "list.ini") # read previous content of ini previous_params <- readIniFile(file = path_clusters_ini) - if (tolower(cluster_name) %in% tolower(names(previous_params)) & !overwrite){ + if (lower_cluster_name %in% tolower(names(previous_params)) & !overwrite){ stop(paste(cluster_name, "already exist")) - } else if (tolower(cluster_name) %in% tolower(names(previous_params)) & overwrite){ - ind_cluster <- which(tolower(names(previous_params)) %in% tolower(cluster_name))[1] + } else if (lower_cluster_name %in% tolower(names(previous_params)) & overwrite){ + ind_cluster <- which(tolower(names(previous_params)) %in% lower_cluster_name)[1] previous_params[[ind_cluster]] <- params_cluster names(previous_params)[[ind_cluster]] <- cluster_name } else { @@ -385,7 +386,7 @@ createClusterRES <- function(area, # initialize series dir.create( - path = file.path(inputPath, cluster_type, "series", tolower(area), tolower(cluster_name)), + path = file.path(inputPath, cluster_type, "series", area, lower_cluster_name), recursive = TRUE, showWarnings = FALSE ) @@ -401,33 +402,33 @@ createClusterRES <- function(area, time_series <- rbind(time_series, fill_mat) } - utils::write.table( + fwrite( x = time_series, row.names = FALSE, col.names = FALSE, sep = "\t", - file = file.path(inputPath, cluster_type, "series", tolower(area), tolower(cluster_name), "series.txt") + file = file.path(inputPath, cluster_type, "series", area, lower_cluster_name, "series.txt") ) # prepro if (identical(cluster_type, "thermal")) { dir.create( - path = file.path(inputPath, cluster_type, "prepro", tolower(area), tolower(cluster_name)), + path = file.path(inputPath, cluster_type, "prepro", area, lower_cluster_name), recursive = TRUE, showWarnings = FALSE ) if (is.null(prepro_data)) prepro_data <- matrix(data = c(rep(1, times = 365 * 2), rep(0, times = 365 * 4)), ncol = 6) - utils::write.table( + fwrite( x = prepro_data, row.names = FALSE, col.names = FALSE, sep = "\t", - file = file.path(inputPath, cluster_type, "prepro", tolower(area), tolower(cluster_name), "data.txt") + file = file.path(inputPath, cluster_type, "prepro", area, lower_cluster_name, "data.txt") ) if (is.null(prepro_modulation)) prepro_modulation <- matrix(data = c(rep(1, times = 365 * 24 * 3), rep(0, times = 365 * 24 * 1)), ncol = 4) - utils::write.table( + fwrite( x = prepro_modulation, row.names = FALSE, col.names = FALSE, sep = "\t", - file = file.path(inputPath, cluster_type, "prepro", tolower(area), tolower(cluster_name), "modulation.txt") + file = file.path(inputPath, cluster_type, "prepro", area, lower_cluster_name, "modulation.txt") ) } diff --git a/R/editCluster.R b/R/editCluster.R index 94c96fbe..904f0c0e 100644 --- a/R/editCluster.R +++ b/R/editCluster.R @@ -86,7 +86,7 @@ editClusterRES <- function(area, ) } - +#' @importFrom data.table fwrite .editCluster <- function(area, cluster_name, ..., @@ -108,6 +108,8 @@ editClusterRES <- function(area, if (add_prefix) cluster_name <- paste(area, cluster_name, sep = "_") + lower_cluster_name <- tolower(cluster_name) + # v860 pollutants if(opts$antaresVersion >= 860) params_cluster <- append(params_cluster, list_pollutants) @@ -117,8 +119,8 @@ editClusterRES <- function(area, opts= opts)) if (!cluster_name %in% clusters){ - if (tolower(cluster_name) %in% tolower(clusters)){ - cluster_idx <- which(tolower(clusters) %in% tolower(cluster_name)) + if (lower_cluster_name %in% tolower(clusters)){ + cluster_idx <- which(tolower(clusters) %in% lower_cluster_name) cluster_name <- clusters[cluster_idx] if (length(cluster_name) > 1) warning("detected multiple clusters : ", do.call(paste, as.list(cluster_name)), ", only the first one will be edited.") @@ -160,7 +162,7 @@ editClusterRES <- function(area, if (!identical(cluster_type, "renewables") && !is.null(prepro_modulation)) { cmd <- api_command_generate( action = "replace_matrix", - target = sprintf("input/thermal/prepro/%s/%s/modulation", area, tolower(cluster_name)), + target = sprintf("input/thermal/prepro/%s/%s/modulation", area, lower_cluster_name), matrix = prepro_modulation ) api_command_register(cmd, opts = opts) @@ -175,7 +177,7 @@ editClusterRES <- function(area, if (!identical(cluster_type, "renewables") && !is.null(prepro_data)) { cmd <- api_command_generate( action = "replace_matrix", - target = sprintf("input/thermal/prepro/%s/%s/data", area, tolower(cluster_name)), + target = sprintf("input/thermal/prepro/%s/%s/data", area, lower_cluster_name), matrix = prepro_data ) api_command_register(cmd, opts = opts) @@ -191,7 +193,7 @@ editClusterRES <- function(area, currPath <- ifelse(identical(cluster_type, "renewables"), "input/renewables/series/%s/%s/series", "input/thermal/series/%s/%s/series") cmd <- api_command_generate( action = "replace_matrix", - target = sprintf(currPath, area, tolower(cluster_name)), + target = sprintf(currPath, area, lower_cluster_name), matrix = time_series ) api_command_register(cmd, opts = opts) @@ -210,14 +212,14 @@ editClusterRES <- function(area, # path to ini file - path_clusters_ini <- file.path(inputPath, cluster_type, "clusters", tolower(area), "list.ini") + path_clusters_ini <- file.path(inputPath, cluster_type, "clusters", area, "list.ini") if (!file.exists(path_clusters_ini)) stop("'", cluster_name, "' in area '", area, "' doesn't seems to exist.") # read previous content of ini previous_params <- readIniFile(file = path_clusters_ini) - if (!tolower(cluster_name) %in% tolower(names(previous_params))){ + if (!lower_cluster_name %in% tolower(names(previous_params))){ stop( "'", cluster_name, "' doesn't exist, it can't be edited. You can create cluster with createCluster().", call. = FALSE @@ -238,23 +240,23 @@ editClusterRES <- function(area, # datas associated with cluster if (!is.null(time_series)) { - utils::write.table( + fwrite( x = time_series, row.names = FALSE, col.names = FALSE, sep = "\t", - file = file.path(inputPath, cluster_type, "series", tolower(area), tolower(cluster_name), "series.txt") + file = file.path(inputPath, cluster_type, "series", area, lower_cluster_name, "series.txt") ) } if (!is.null(prepro_data)) { - utils::write.table( + fwrite( x = prepro_data, row.names = FALSE, col.names = FALSE, sep = "\t", - file = file.path(inputPath, cluster_type, "prepro", tolower(area), tolower(cluster_name), "data.txt") + file = file.path(inputPath, cluster_type, "prepro", area, lower_cluster_name, "data.txt") ) } if (!is.null(prepro_modulation)) { - utils::write.table( + fwrite( x = prepro_modulation, row.names = FALSE, col.names = FALSE, sep = "\t", - file = file.path(inputPath, cluster_type, "prepro", tolower(area), tolower(cluster_name), "modulation.txt") + file = file.path(inputPath, cluster_type, "prepro", area, lower_cluster_name, "modulation.txt") ) }