From 6638046e0a107ef24692c969c85f5b662e7d36cc Mon Sep 17 00:00:00 2001 From: kemihak Date: Fri, 26 Apr 2024 16:22:04 +0200 Subject: [PATCH 1/3] Add specific case to avoid bad convert --- R/readIniFile.R | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/R/readIniFile.R b/R/readIniFile.R index eda11d6..a5a8379 100644 --- a/R/readIniFile.R +++ b/R/readIniFile.R @@ -58,14 +58,18 @@ readIni <- function(pathIni, opts = antaresRead::simOptions(), default_ext = ".i #' @export #' @rdname read-ini readIniFile <- function(file, stringsAsFactors = FALSE) { + X <- readLines(file) sections <- grep("^\\[.*\\]$", X) starts <- sections + 1 ends <- c(sections[-1] - 1, length(X)) L <- vector(mode = "list", length = length(sections)) names(L) <- gsub("\\[|\\]", "", X[sections]) + for(i in seq(along = sections)) { + if (starts[i] >= ends[i]) next + pairs <- X[seq(starts[i], ends[i])] pairs <- pairs[pairs != ""] pairs <- strsplit(pairs, "=") @@ -76,13 +80,17 @@ readIniFile <- function(file, stringsAsFactors = FALSE) { value <- lapply(pairs, `[`, 2) value <- as.list(trimws(unlist(value))) - value <- lapply(value, function(x) { + value <- lapply(value, function(x){ if (tolower(x) %in% c("true", "false")) { tolower(x) == "true" + } else if(!identical(grep(pattern = "^[0-9]+(e|i)$", x = x), integer(0))) { + # Not convert those type of values : 789e or 789i (complex number) + as.character(x) } else { utils::type.convert(x, as.is = TRUE) } - }) + } + ) L[[i]] <- value names(L[[i]]) <- key @@ -90,6 +98,7 @@ readIniFile <- function(file, stringsAsFactors = FALSE) { L } + #' @param study_id Study's identifier. #' @param path Path of configuration object to read. #' @param host Host of AntaREST server API. From 1db78a47fadfcd7ec27ba6b27dbcfa0fe2e8375a Mon Sep 17 00:00:00 2001 From: kemihak Date: Fri, 26 Apr 2024 16:22:36 +0200 Subject: [PATCH 2/3] Add unit test file for readIniFile --- tests/testthat/test-readIni.R | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 tests/testthat/test-readIni.R diff --git a/tests/testthat/test-readIni.R b/tests/testthat/test-readIni.R new file mode 100644 index 0000000..caf8573 --- /dev/null +++ b/tests/testthat/test-readIni.R @@ -0,0 +1,24 @@ +test_that("First test", { + + con <- file.path(tempdir(),"testReadIniFile.ini") + file.create(path = con) + cluster_list_ini_content <- c("[zone1_nuclear]", "group = Other", "name = zone1_nuclear", "test = true", "", + "[92i]", "group = Other", "name = 92i", "test = true", "", + "[zone1_gas]", "group = Other", "name = zone1_gas", "test = false", "", + "[7983e]", "group = Other", "name = 7983e", "test = true", "", + "[zone1_coal]", "group = Other", "name = zone1_coal", "test = false", "" + ) + writeLines(text = cluster_list_ini_content, con = con) + + clusters <- readIniFile(con) + + # Specific cases not converted : 92i and 7983e + clusters_name <- sapply(clusters, "[[", "name") + clusters_name <- unname(clusters_name) + expect_identical(clusters_name, c("zone1_nuclear", "92i", "zone1_gas", "7983e", "zone1_coal")) + + # Boolean + clusters_test <- sapply(clusters, "[[", "test") + clusters_test <- unname(clusters_test) + expect_true(class(clusters_test) == "logical") +}) From 79dec6df22f57b3c9b5a636dd5756b6bf89b625b Mon Sep 17 00:00:00 2001 From: kemihak Date: Mon, 29 Apr 2024 09:21:55 +0200 Subject: [PATCH 3/3] Update NEWS.md and DESCRIPTION files --- DESCRIPTION | 2 +- NEWS.md | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 33f7e46..6224560 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: antaresRead Type: Package Title: Import, Manipulate and Explore the Results of an 'Antares' Simulation -Version: 2.6.1 +Version: 2.6.2 Authors@R: c( person("Tatiana", "Vargas", email = "tatiana.vargas@rte-france.com", role = c("aut", "cre")), person("Jalal-Edine", "ZAWAM", role = "aut"), diff --git a/NEWS.md b/NEWS.md index 9eb17f4..0c3f610 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,19 @@ > Copyright © 2016 RTE Réseau de transport d’électricité +# antaresRead 2.6.2 (development) + +NEW FEATURES : + +BUGFIXES : +* `readIniFile()` : avoid `utils::type.convert` on specific cases (ex : 789e or 123i) + +BREAKING CHANGES : + +DATA : + +PERFORMANCE : + + # antaresRead 2.6.1 BUGFIXES :