Commit e611fca1 authored by Dorchies David's avatar Dorchies David
Browse files

fix(CreateInputsCrit): wrong data in Lavenne criterion function

Closes #57
parent 1835bfeb
......@@ -82,15 +82,29 @@ CreateInputsCrit.GRiwrmInputsModel <- function(InputsModel,
return(InputsCrit)
}
#' Generate a `CreateInputsCrit_Lavenne` function which embeds know parameters
#'
#' The created function will be used in calibration for injecting necessary `AprParamR` and `AprCrit`
#' parameters, which can be known only during calibration process, in the call of `CreateInputsCrit_Lavenne`.
#'
#' @param InputsModel See [CreateInputsCrit] parameters
#' @param FUN_CRIT See [CreateInputsCrit] parameters
#' @param RunOptions See [CreateInputsCrit] parameters
#' @param Obs See [CreateInputsCrit] parameters
#' @param k See [CreateInputsCrit] parameters
#' @param ... further arguments for [airGR::CreateInputsCrit_Lavenne]
#'
#' @return A function with `AprParamR` and `AprCrit`
#' @noRd
#'
CreateLavenneFunction <- function(InputsModel, FUN_CRIT, RunOptions, Obs, k, ...) {
# The following line solve the issue #57 by forcing the evaluation of all the parameters.
# See also: https://stackoverflow.com/questions/69016698/is-there-a-bug-on-closures-embedded-in-a-list-in-r/69028161#69028161
arguments <- c(as.list(environment()), list(...))
function(AprParamR, AprCrit) {
CreateInputsCrit_Lavenne(FUN_CRIT = FUN_CRIT,
InputsModel = InputsModel,
RunOptions = RunOptions,
Obs = Obs,
AprParamR = AprParamR,
AprCrit = AprCrit,
k = k,
...)
do.call(
CreateInputsCrit_Lavenne,
c(arguments, list(AprParamR = AprParamR, AprCrit = AprCrit))
)
}
}
......@@ -37,7 +37,14 @@ test_that("De Lavenne criterion is OK", {
expect_s3_class(IC57, "Compo")
})
test_that("De Lavenne criterion: wrong sub-catchment order should throw error", {
test_that("Lavenne embedded data is correct #57", {
lapply(names(AprioriIds), function(id) {
p <- as.list(environment(attr(IC[[id]], "Lavenne_FUN")))
expect_equal(id, p$InputsModel$id)
})
})
test_that("Lavenne criterion: wrong sub-catchment order should throw error", {
expect_error(
CreateInputsCrit(InputsModel = InputsModel,
RunOptions = RunOptions,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment