Skip to content

Commit

Permalink
updateGeneralSettings() : replace argument name (#165)
Browse files Browse the repository at this point in the history
* Add package lifecycle in Imports section

* Update NEWS.md

* Replace custom.ts.numbers by custom.scenario in updateGeneralSettings()

* Changes after code review
  • Loading branch information
KKamel67 authored Jul 30, 2024
1 parent 6ea3a09 commit f98431f
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 53 deletions.
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,9 @@ importFrom(httr,stop_for_status)
importFrom(httr,upload_file)
importFrom(jsonlite,toJSON)
importFrom(jsonlite,write_json)
importFrom(lifecycle,deprecate_warn)
importFrom(lifecycle,deprecated)
importFrom(lifecycle,is_present)
importFrom(memuse,Sys.meminfo)
importFrom(plyr,ldply)
importFrom(plyr,llply)
Expand Down
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ BUGFIXES :
* side effects with `readClusterDesc()` / `readClusterResDesc()` / `readClusterSTDesc()`


OTHER UPDATES :
* `updateGeneralSettings()` : replace custom.ts.numbers argument by custom.scenario and deprecate custom.ts.numbers

# antaresEditObject 0.7.0

> Scenarized RHS for binding constraints
Expand Down
84 changes: 51 additions & 33 deletions R/updateGeneralSettings.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,34 +19,38 @@
#' printed out in an individual directory7 :
#' Study_name/OUTPUT/simu_tag/Economy /mc-i-number
#' @param derated See Antares General Reference Guide.
#' @param custom.ts.numbers See Antares General Reference Guide.
#' @param user.playlist See Antares General Reference Guide.
#' @param filtering See Antares General Reference Guide.
#' @param active.rules.scenario See Antares General Reference Guide.
#' @param generate See Antares General Reference Guide.
#' @param nbtimeseriesload See Antares General Reference Guide.
#' @param nbtimeserieshydro See Antares General Reference Guide.
#' @param nbtimeserieswind See Antares General Reference Guide.
#' @param nbtimeseriesthermal See Antares General Reference Guide.
#' @param nbtimeseriessolar See Antares General Reference Guide.
#' @param refreshtimeseries See Antares General Reference Guide.
#' @param intra.modal See Antares General Reference Guide.
#' @param inter.modal See Antares General Reference Guide.
#' @param refreshintervalload See Antares General Reference Guide.
#' @param refreshintervalhydro See Antares General Reference Guide.
#' @param refreshintervalwind See Antares General Reference Guide.
#' @param refreshintervalthermal See Antares General Reference Guide.
#' @param refreshintervalsolar See Antares General Reference Guide.
#' @param readonly See Antares General Reference Guide.
#' @param custom.scenario See Antares General Reference Guide (see link below). Replace custom.ts.numbers.
#' @param custom.ts.numbers See Antares General Reference Guide (see link below). Replaced by custom.scenario.
#' @param user.playlist See Antares General Reference Guide (see link below).
#' @param filtering See Antares General Reference Guide (see link below).
#' @param active.rules.scenario See Antares General Reference Guide (see link below).
#' @param generate See Antares General Reference Guide (see link below).
#' @param nbtimeseriesload See Antares General Reference Guide (see link below).
#' @param nbtimeserieshydro See Antares General Reference Guide (see link below).
#' @param nbtimeserieswind See Antares General Reference Guide (see link below).
#' @param nbtimeseriesthermal See Antares General Reference Guide (see link below).
#' @param nbtimeseriessolar See Antares General Reference Guide (see link below).
#' @param refreshtimeseries See Antares General Reference Guide (see link below).
#' @param intra.modal See Antares General Reference Guide (see link below).
#' @param inter.modal See Antares General Reference Guide (see link below).
#' @param refreshintervalload See Antares General Reference Guide (see link below).
#' @param refreshintervalhydro See Antares General Reference Guide (see link below).
#' @param refreshintervalwind See Antares General Reference Guide (see link below).
#' @param refreshintervalthermal See Antares General Reference Guide (see link below).
#' @param refreshintervalsolar See Antares General Reference Guide (see link below).
#' @param readonly See Antares General Reference Guide (see link below).
#' @param geographic.trimming \code{logical} indicates whether to store the results for all time spans (FALSE) or for custom time spans (TRUE)
#' @template opts
#'
#' @export
#'
#' @importFrom utils modifyList
#' @importFrom assertthat assert_that
#' @importFrom antaresRead setSimulationPath
#' @importFrom antaresRead setSimulationPath readIniFile
#' @importFrom lifecycle is_present deprecate_warn deprecated
#'
#' @seealso \href{https://antares-simulator--2010.org.readthedocs.build/en/2010/reference-guide/18-parameters}{Antares General Reference Guide}
#'
#' @examples
#' \dontrun{
#'
Expand All @@ -69,7 +73,8 @@ updateGeneralSettings <- function(mode = NULL,
leapyear = NULL,
year.by.year = NULL,
derated = NULL,
custom.ts.numbers = NULL,
custom.scenario = NULL,
custom.ts.numbers = deprecated(),
user.playlist = NULL,
filtering = NULL,
active.rules.scenario = NULL,
Expand All @@ -93,6 +98,15 @@ updateGeneralSettings <- function(mode = NULL,

assertthat::assert_that(inherits(opts, "simOptions"))

# Replace custom.ts.numbers argument by custom.scenario
if (lifecycle::is_present(custom.ts.numbers)) {
lifecycle::deprecate_warn(when = "0.7.1",
what = "updateGeneralSettings(custom.ts.numbers = )",
with = "updateGeneralSettings(custom.scenario = )"
)
custom.scenario <- custom.ts.numbers
}

intra.modal <- check_param_modal(intra.modal, opts)
inter.modal <- check_param_modal(inter.modal, opts)

Expand All @@ -115,7 +129,7 @@ updateGeneralSettings <- function(mode = NULL,
leapyear = leapyear,
year.by.year = year.by.year,
derated = derated,
custom.ts.numbers = custom.ts.numbers,
custom.scenario = custom.scenario,
user.playlist = user.playlist,
filtering = filtering,
active.rules.scenario = active.rules.scenario,
Expand All @@ -136,11 +150,18 @@ updateGeneralSettings <- function(mode = NULL,
readonly = readonly,
geographic.trimming = geographic.trimming
)
new_params <- dropNulls(new_params)
for (i in seq_along(new_params)) {
new_params[[i]] <- paste(as.character(new_params[[i]]), collapse = ", ")
names(new_params)[i] <- dicoGeneralSettings(names(new_params)[i])
}

new_params <- dropNulls(x = new_params)
# Convert logical to a lower case character to match the default existing file
new_params <- lapply(X = new_params,
FUN = function(new_param){
if (inherits(x = new_param, what = "logical")) {
new_param <- tolower(as.character(new_param))
}
paste(as.character(new_param), collapse = ", ")
}
)
names(new_params) <- sapply(names(new_params), dicoGeneralSettings, USE.NAMES = FALSE)

# API block
if (is_api_study(opts)) {
Expand All @@ -165,7 +186,7 @@ updateGeneralSettings <- function(mode = NULL,

# Maj simulation
suppressWarnings({
res <- antaresRead::setSimulationPath(path = opts$studyPath, simulation = "input")
res <- setSimulationPath(path = opts$studyPath, simulation = "input")
})

invisible(res)
Expand Down Expand Up @@ -249,7 +270,7 @@ dicoGeneralSettings <- function(arg) {
antares_params <- as.list(
c("mode", "horizon", "nbyears", "simulation.start", "simulation.end",
"january.1st", "first-month-in-year", "first.weekday", "leapyear",
"year-by-year", "derated", "custom-ts-numbers", "user-playlist",
"year-by-year", "derated", "custom-scenario", "user-playlist",
"filtering", "active-rules-scenario", "generate", "nbtimeseriesload",
"nbtimeserieshydro", "nbtimeserieswind", "nbtimeseriesthermal",
"nbtimeseriessolar", "refreshtimeseries", "intra-modal", "inter-modal",
Expand All @@ -258,14 +279,11 @@ dicoGeneralSettings <- function(arg) {
)
names(antares_params) <- c("mode", "horizon", "nbyears", "simulation.start", "simulation.end",
"january.1st", "first.month.in.year", "first.weekday", "leapyear",
"year.by.year", "derated", "custom.ts.numbers", "user.playlist",
"year.by.year", "derated", "custom.scenario", "user.playlist",
"filtering", "active.rules.scenario", "generate", "nbtimeseriesload",
"nbtimeserieshydro", "nbtimeserieswind", "nbtimeseriesthermal",
"nbtimeseriessolar", "refreshtimeseries", "intra.modal", "inter.modal",
"refreshintervalload", "refreshintervalhydro", "refreshintervalwind",
"refreshintervalthermal", "refreshintervalsolar", "readonly", "geographic.trimming")
antares_params[[arg]]
}



46 changes: 26 additions & 20 deletions man/updateGeneralSettings.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions tests/testthat/test-updateGeneralSettings.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,23 @@ sapply(studies, function(study) {
unlink(x = file.path(pathstd, "test_case"), recursive = TRUE)

})


# custom-scenario ----
test_that("updateGeneralSettings() : check appearance of property custom-scenario and check if it is written in lowercase", {

ant_version <- "8.2.0"
st_test <- paste0("my_study_820_", paste0(sample(letters,5),collapse = ""))
suppressWarnings(opts <- createStudy(path = pathstd, study_name = st_test, antares_version = ant_version))

# custom-scenario (logical)
expect_false(getOption("antares")$parameters$general$`custom-scenario`)
updateGeneralSettings(custom.scenario = TRUE)
expect_true(getOption("antares")$parameters$general$`custom-scenario`)
# check lower case for a logical value
lines_generaldata <- readLines(file.path(opts$studyPath, "settings", "generaldata.ini"))
expect_false(paste0(dicoGeneralSettings("custom.scenario"), " = TRUE") %in% lines_generaldata)
expect_true(paste0(dicoGeneralSettings("custom.scenario"), " = true") %in% lines_generaldata)

unlink(x = opts$studyPath, recursive = TRUE)
})

0 comments on commit f98431f

Please sign in to comment.