Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
IN-WOP
airGRiwrm
Commits
e611fca1
Commit
e611fca1
authored
Sep 03, 2021
by
Dorchies David
Browse files
fix(CreateInputsCrit): wrong data in Lavenne criterion function
Closes
#57
parent
1835bfeb
Changes
2
Hide whitespace changes
Inline
Side-by-side
R/CreateInputsCrit.GRiwrmInputsModel.R
View file @
e611fca1
...
...
@@ -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
))
)
}
}
tests/testthat/test-CreateInputsCrit.R
View file @
e611fca1
...
...
@@ -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
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment