From 92d92b018a6563a44b35ef1fc116889dc0091e9b Mon Sep 17 00:00:00 2001 From: berthetclement Date: Tue, 15 Oct 2024 17:21:01 +0200 Subject: [PATCH 1/4] up version to dev .9000 + add temporary remotes to antaresRead --- DESCRIPTION | 4 +++- NEWS.md | 10 ++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index cafc108..8e2c5a4 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: antaresEditObject Type: Package Title: Edit an 'Antares' Simulation -Version: 0.7.1 +Version: 0.8.0.9000 Authors@R: c( person("Tatiana", "Vargas", email = "tatiana.vargas@rte-france.com", role = c("aut", "cre")), person("Frederic", "Breant", role = "ctb"), @@ -53,3 +53,5 @@ Suggests: knitr, rmarkdown VignetteBuilder: knitr +Remotes: + rte-antares-rpackage/antaresRead@feature/ant1795v2 diff --git a/NEWS.md b/NEWS.md index 08ab744..c073378 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,13 @@ +> Copyright © 2016 RTE Reseau de transport d’electricite + +# antaresEditObject 0.8.0.9000 +(cf. Antares v9 changelog) + +NEW FEATURES (Antares v9.0) : +* `createStudy()` takes into account the new format of Antares studies (e.g. 9.0, 9.15 instead of 900, 915) + + + # antaresEditObject 0.7.1 ### Breaking changes : From 26824a9f5fd0e226ab912f089231bab15b611549 Mon Sep 17 00:00:00 2001 From: berthetclement Date: Tue, 15 Oct 2024 17:21:51 +0200 Subject: [PATCH 2/4] update createStudy() txt mode to create study v9 + doc + tests --- R/createStudy.R | 71 +++++++++++++++++++++++++++---- man/create-study.Rd | 17 +++++++- tests/testthat/test-createStudy.R | 35 +++++++++++++++ 3 files changed, 114 insertions(+), 9 deletions(-) diff --git a/R/createStudy.R b/R/createStudy.R index 376e0a8..b079803 100644 --- a/R/createStudy.R +++ b/R/createStudy.R @@ -7,6 +7,11 @@ #' if it doesn't exist, it'll be created. #' @param study_name Name of the study. #' @param antares_version Antares number version. +#' +#' @section Warning: +#' From **Antares version 9.0** onwards, versioning is only done with one number +#' for the major version number and a two-digit number for the minor +#' version number (e.g. 9.0, 9.12, 10.58, ...). #' #' @return Result of [antaresRead::setSimulationPath()] or [antaresRead::setSimulationPathAPI()] accordingly. #' @export @@ -20,11 +25,39 @@ #' @examples #' \dontrun{ #' -#' createStudy("path/to/simulation") +#' # with default values +#' createStudy("path/to/simulation", +#' study_name = "my_study", +#' antares_version = "8.2.0") +#' +#' # with Antares study version >= 9 (max 2 digits, ex : "9.15") +#' createStudy("path/to/simulation", +#' study_name = "my_study", +#' antares_version = "9.15") #' #' } createStudy <- function(path, study_name = "my_study", antares_version = "8.2.0") { antares_version <- as.numeric_version(antares_version) + + # Split major and minor parts + antares_version_splitted <- unlist( + strsplit( + as.character(antares_version), + split = "\\.")) + major <- antares_version_splitted[1] + + # check from version 9, minor max two digits + is_new_version <- as.numeric(major)>=9 + if(is_new_version){ + minor <- antares_version_splitted[2] + if(length(antares_version_splitted)>2) + stop("From Antares version 9, put version like this : '9.0' or '9.12' or '10.25'", + call. = FALSE) + if (nchar(minor) > 2) + stop("Invalid antares_version format, good format is like '9.99' (two digits on minor)", + call. = FALSE) + } + if (!dir.exists(path)) { dir.create(path = path, recursive = TRUE) } else { @@ -35,6 +68,8 @@ createStudy <- function(path, study_name = "my_study", antares_version = "8.2.0" } } } + + # choose template if (antares_version < as.numeric_version("6.5.0")) { file.copy( from = list.files(path = system.file("newStudy", package = "antaresEditObject"), full.names = TRUE), @@ -51,15 +86,31 @@ createStudy <- function(path, study_name = "my_study", antares_version = "8.2.0" } else { unzip(zipfile = system.file("template-antares/antares-study-v800.zip", package = "antaresEditObject"), exdir = path) } + + # read ".antares" file to update antares <- paste(readLines(con = file.path(path, "study.antares")), collapse = "\n") - antares <- whisker::whisker.render( - template = antares, - data = list( - version = gsub(pattern = ".", replacement = "", x = antares_version, fixed = TRUE), - study_name = study_name, - date_created = floor(as.numeric(Sys.time())) + + # specific format from version 9 + if(is_new_version) + antares <- whisker::whisker.render( + template = antares, + data = list( + version = antares_version, + study_name = study_name, + date_created = floor(as.numeric(Sys.time())) + ) ) - ) + else + antares <- whisker::whisker.render( + template = antares, + data = list( + version = gsub(pattern = ".", replacement = "", x = antares_version, fixed = TRUE), + study_name = study_name, + date_created = floor(as.numeric(Sys.time())) + ) + ) + + # write meta data writeLines(text = antares, con = file.path(path, "study.antares")) desktop <- paste(readLines(con = file.path(path, "Desktop.ini")), collapse = "\n") desktop <- whisker::whisker.render( @@ -69,7 +120,11 @@ createStudy <- function(path, study_name = "my_study", antares_version = "8.2.0" ) ) writeLines(text = desktop, con = file.path(path, "Desktop.ini")) + + # read study to create meta data object to return then opts <- setSimulationPath(path = path) + + # add specific directory and files according to version of study to create if (antares_version >= as.numeric_version("8.1.0")) { activateRES(opts = opts) } diff --git a/man/create-study.Rd b/man/create-study.Rd index a274b96..f2ce352 100644 --- a/man/create-study.Rd +++ b/man/create-study.Rd @@ -36,10 +36,25 @@ Result of \code{\link[antaresRead:setSimulationPath]{antaresRead::setSimulationP \description{ Create study on disk or with AntaREST server through the API. } +\section{Warning}{ + +From \strong{Antares version 9.0} onwards, versioning is only done with one number +for the major version number and a two-digit number for the minor +version number (e.g. 9.0, 9.12, 10.58, ...). +} + \examples{ \dontrun{ -createStudy("path/to/simulation") +# with default values +createStudy("path/to/simulation", + study_name = "my_study", + antares_version = "8.2.0") + +# with Antares study version >= 9 (max 2 digits, ex : "9.15") +createStudy("path/to/simulation", + study_name = "my_study", + antares_version = "9.15") } } diff --git a/tests/testthat/test-createStudy.R b/tests/testthat/test-createStudy.R index b2a4d73..e8cf304 100644 --- a/tests/testthat/test-createStudy.R +++ b/tests/testthat/test-createStudy.R @@ -2,6 +2,41 @@ # create ---- + ## v9.0---- +test_that("Create a new v9.0 study", { + path <- file.path(tempdir(), "tests_createStudy") + suppressWarnings( + opts <- createStudy(path, antares_version = "9.0") + ) + properties <- antaresRead:::readIniFile(file.path(path, "study.antares")) + expect_identical(properties$antares$version, 9) + unlink(path, recursive = TRUE) +}) + +test_that("Create a new v9.15 (2 digits) study", { + path <- file.path(tempdir(), "tests_createStudy") + suppressWarnings( + opts <- createStudy(path, antares_version = "9.15") + ) + properties <- antaresRead:::readIniFile(file.path(path, "study.antares")) + expect_identical(properties$antares$version, 9.15) + unlink(path, recursive = TRUE) +}) + +test_that("Create a new v9.15.2 (error bad format version) study", { + path <- file.path(tempdir(), "tests_createStudy") + + expect_error( + opts <- createStudy(path, antares_version = "9.15.2"), + regexp = 'From Antares version 9, put version like this : \'9.0\' or') + + expect_error( + opts <- createStudy(path, antares_version = "9.153"), + regexp = "Invalid antares_version format, good format is like \'9.99\' \\(two digits on minor\\)" ) + + unlink(path, recursive = TRUE) +}) + ## v8.7.0---- test_that("Create a new v8.7.0 study", { path <- file.path(tempdir(), "tests_createStudy") From 6e6b15736e1d0b132f44a1f7945f8528077f82c1 Mon Sep 17 00:00:00 2001 From: berthetclement Date: Wed, 16 Oct 2024 12:26:14 +0200 Subject: [PATCH 3/4] createStudy() minor rewrites and refacto --- R/createStudy.R | 84 ++++++++++++++++++++++++----------------- man/dot-is_version_9.Rd | 18 +++++++++ 2 files changed, 67 insertions(+), 35 deletions(-) create mode 100644 man/dot-is_version_9.Rd diff --git a/R/createStudy.R b/R/createStudy.R index b079803..afc66d3 100644 --- a/R/createStudy.R +++ b/R/createStudy.R @@ -39,24 +39,8 @@ createStudy <- function(path, study_name = "my_study", antares_version = "8.2.0") { antares_version <- as.numeric_version(antares_version) - # Split major and minor parts - antares_version_splitted <- unlist( - strsplit( - as.character(antares_version), - split = "\\.")) - major <- antares_version_splitted[1] - - # check from version 9, minor max two digits - is_new_version <- as.numeric(major)>=9 - if(is_new_version){ - minor <- antares_version_splitted[2] - if(length(antares_version_splitted)>2) - stop("From Antares version 9, put version like this : '9.0' or '9.12' or '10.25'", - call. = FALSE) - if (nchar(minor) > 2) - stop("Invalid antares_version format, good format is like '9.99' (two digits on minor)", - call. = FALSE) - } + # check format version >= 9 + is_new_version <- .is_version_9(version = antares_version) if (!dir.exists(path)) { dir.create(path = path, recursive = TRUE) @@ -88,27 +72,27 @@ createStudy <- function(path, study_name = "my_study", antares_version = "8.2.0" } # read ".antares" file to update - antares <- paste(readLines(con = file.path(path, "study.antares")), collapse = "\n") + antares <- paste(readLines(con = file.path(path, "study.antares")), + collapse = "\n") # specific format from version 9 - if(is_new_version) - antares <- whisker::whisker.render( - template = antares, - data = list( - version = antares_version, - study_name = study_name, - date_created = floor(as.numeric(Sys.time())) - ) - ) + if(!is_new_version) + version_to_write <- gsub(pattern = ".", + replacement = "", + x = antares_version, + fixed = TRUE) else - antares <- whisker::whisker.render( - template = antares, - data = list( - version = gsub(pattern = ".", replacement = "", x = antares_version, fixed = TRUE), - study_name = study_name, - date_created = floor(as.numeric(Sys.time())) - ) + version_to_write <- antares_version + + # template for file "study.antares" + antares <- whisker::whisker.render( + template = antares, + data = list( + version = version_to_write, + study_name = study_name, + date_created = floor(as.numeric(Sys.time())) ) + ) # write meta data writeLines(text = antares, con = file.path(path, "study.antares")) @@ -223,3 +207,33 @@ deleteStudy <- function(opts = simOptions(), prompt_validation = FALSE, simulati "Study"))) } + +#' function that ensures the transition to 9 +#' @description basic tests on the version's writing format +#' +#' @param version `character` (eg, "8.2.0" or "9.0") +#' @return `logical` if version >=9 +#' @keywords internal +.is_version_9 <- function(version){ + # Split major and minor parts + antares_version_splitted <- unlist( + strsplit( + as.character(version), + split = "\\.")) + major <- antares_version_splitted[1] + + # check from version 9, minor max two digits + is_new_version <- as.numeric(major)>=9 + if(is_new_version){ + minor <- antares_version_splitted[2] + if(length(antares_version_splitted)>2) + stop("From Antares version 9, put version like this : '9.0' or '9.12' or '10.25'", + call. = FALSE) + if (nchar(minor) > 2) + stop("Invalid antares_version format, good format is like '9.99' (two digits on minor)", + call. = FALSE) + } + + return(is_new_version) +} + diff --git a/man/dot-is_version_9.Rd b/man/dot-is_version_9.Rd new file mode 100644 index 0000000..deebbb5 --- /dev/null +++ b/man/dot-is_version_9.Rd @@ -0,0 +1,18 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/createStudy.R +\name{.is_version_9} +\alias{.is_version_9} +\title{function that ensures the transition to 9} +\usage{ +.is_version_9(version) +} +\arguments{ +\item{version}{\code{character} (eg, "8.2.0" or "9.0")} +} +\value{ +\code{logical} if version >=9 +} +\description{ +basic tests on the version's writing format +} +\keyword{internal} From 19a88b79967e706c9f1d47a46be69de96f3a2a6c Mon Sep 17 00:00:00 2001 From: berthetclement Date: Wed, 16 Oct 2024 15:38:03 +0200 Subject: [PATCH 4/4] update remote to master --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 8e2c5a4..403e657 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -54,4 +54,4 @@ Suggests: rmarkdown VignetteBuilder: knitr Remotes: - rte-antares-rpackage/antaresRead@feature/ant1795v2 + rte-antares-rpackage/antaresRead