Skip to content

Commit

Permalink
setSimulationPathAPI fix parameter "simulation" with negativ values
Browse files Browse the repository at this point in the history
  • Loading branch information
BERTHET Clement (Externe) committed Oct 30, 2023
1 parent 97ee726 commit 54cdeb6
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)

Check warning on line 251 in R/setSimulationPath.R

View check run for this annotation

Codecov / codecov/patch

R/setSimulationPath.R#L250-L251

Added lines #L250 - L251 were not covered by tests
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"))

Check warning on line 50 in R/utils_api.R

View check run for this annotation

Codecov / codecov/patch

R/utils_api.R#L50

Added line #L50 was not covered by tests
}
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,

Check warning on line 199 in R/utils_api.R

View check run for this annotation

Codecov / codecov/patch

R/utils_api.R#L199

Added line #L199 was not covered by tests
synthesis = synthesis,
yearByYear = yearByYear,
scenarios = scenarios,
Expand Down

0 comments on commit 54cdeb6

Please sign in to comment.