Skip to content

Commit

Permalink
Merge pull request #223 from rte-antares-rpackage/ant775/fix_option_s…
Browse files Browse the repository at this point in the history
…imulation

setSimulationPathAPI fix parameter "simulation" with negativ values
  • Loading branch information
berthetclement authored Oct 31, 2023
2 parents 97ee726 + 54cdeb6 commit 918bc0d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
4 changes: 3 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

BUGFIXES :

* `setSimulationPathAPI()` error message with bad id
* `setSimulationPathAPI()` :
- returns an API exception if the requested study ID is incorrect
- `simulation` the simulation parameter works with negative values within the limit of the number of simulations
* correction in `readClusterDesc()` calls to add "opts"


Expand Down
9 changes: 7 additions & 2 deletions R/setSimulationPath.R
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,13 @@ setSimulationPath <- function(path, simulation = NULL) {

.giv_sim <- function(simulation, simNames, path){
if (is.numeric(simulation)) {
if (simulation > 0) sim <- simNames[simulation]
else sim <- rev(simNames)[abs(simulation)]
if(abs(simulation)>length(simNames))
stop(paste0("Parameter 'simulation' is greater than
the number of simulations (", length(simNames), ")"), call. = FALSE)
if (simulation > 0)
sim <- simNames[simulation]
else
sim <- rev(simNames)[abs(simulation)]
} else {
if (any(simNames == simulation)) sim <- simulation
else {
Expand Down
3 changes: 2 additions & 1 deletion R/utils_api.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ read_secure_json <- function(url, token = NULL, timeout = 60, config = list()) {
outputPath <- file.path(path, "output")
if(is.null(simulation) | (!is.null(simulation) && !simulation %in% c(0, "input"))){
outputContent <- names(read_secure_json(paste0(outputPath, "&depth=4"), ...))
simNames <- setdiff(basename(outputContent), "maps")
simNames <- setdiff(basename(outputContent), c("maps", "logs"))
}
if (length(simNames) == 0) {
if (length(simulation) > 0 && !simulation %in% c(0, "input")) {
Expand Down Expand Up @@ -196,6 +196,7 @@ read_secure_json <- function(url, token = NULL, timeout = 60, config = list()) {
simDataPath = simDataPath,
name = as.character(info$name),
mode = as.character(info$mode),
simDate = info$date,
synthesis = synthesis,
yearByYear = yearByYear,
scenarios = scenarios,
Expand Down

0 comments on commit 918bc0d

Please sign in to comment.