Skip to content

Commit

Permalink
Merge pull request #2 from VForWaTer/parse_min_max
Browse files Browse the repository at this point in the history
Parse min and max parameter fields.
  • Loading branch information
AlexDo1 authored May 25, 2023
2 parents 3fda946 + f2be160 commit 22fafaf
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions R/get_parameters.R
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,40 @@ get_parameters <- function() {
} else if (ext == "csv") {
val <- read.csv(val)
}
} else if (tolower(t) %in% c("integer", "float")) {
print(t)
# check for min in params_config
if ("min" %in% names(params_config[[name]])) {
min <- params_config[[name]]$min
} else {
min <- NULL
}
# check for max in params_config
if ("max" %in% names(params_config[[name]])) {
max <- params_config[[name]]$max
} else {
max <- NULL
}

# check whether val is in min and max range
if (!is.null(min) && !is.null(max)) {
# check if min is smaller than or equal to max
if (max <= min) {
stop(sprintf("There is an error in your parameter configuration / tool.yml, as the given minimum value (%s) for parameter '%s' is higher than or equal to the maximum number (%s).", min, name, max))
# check if val is between min and max
} else if (!(min <= val && val <= max)) {
stop(sprintf("%s is %s, but it must be between %s and %s.", name, val, min, max))
}
# check if val is greater than or equal to min
} else if (!is.null(min) && !(min <= val)) {
stop(sprintf("%s is %s, but must be higher than or equal to %s.", name, val, min))
# check if val is smaller than or equal to max
} else if (!is.null(max) && !(val <= max)) {
stop(sprintf("%s is %s, but must be smaller than or equal to %s.", name, val, max))
# return val if not violating min-max constraints
} else {
parsed_params[[name]] <- val
}
}

# parse default values for parameters that are still NULL; a default value exists, as the parameter comes from the filtered_config_names
Expand Down

0 comments on commit 22fafaf

Please sign in to comment.