From b84085b2a5d2a9d4239aec46347f866fbc20a387 Mon Sep 17 00:00:00 2001 From: Delaigue Olivier <olivier.delaigue@irstea.priv> Date: Tue, 12 Mar 2019 17:34:34 +0100 Subject: [PATCH] v1.2.9.0 NEW: FUN_* arguments can be a character of the function name --- DESCRIPTION | 2 +- NEWS.rmd | 4 +++- R/Calibration.R | 7 ++++--- R/Calibration_Michel.R | 7 +++++++ R/CreateCalibOptions.R | 22 ++++++++++++---------- R/CreateIniStates.R | 1 + R/CreateInputsCrit.R | 2 ++ R/CreateInputsModel.R | 2 ++ R/CreateRunOptions.R | 2 ++ R/ErrorCrit.R | 2 ++ R/RunModel.R | 1 + R/TransfoParam.R | 1 + 12 files changed, 38 insertions(+), 15 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 71dce2de..842c7d74 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: airGR Type: Package Title: Suite of GR Hydrological Models for Precipitation-Runoff Modelling -Version: 1.2.8.11 +Version: 1.2.9.0 Date: 2019-03-12 Authors@R: c( person("Laurent", "Coron", role = c("aut", "trl"), comment = c(ORCID = "0000-0002-1503-6204")), diff --git a/NEWS.rmd b/NEWS.rmd index 72926193..1c9aa297 100644 --- a/NEWS.rmd +++ b/NEWS.rmd @@ -13,7 +13,7 @@ output: -### 1.2.8.11 Release Notes (2019-03-12) +### 1.2.9.0 Release Notes (2019-03-12) @@ -60,6 +60,8 @@ output: - It is now possible to be redirected on the documantation about <code>plot.OutputsModel()</code> with <code>?plot</code>. +- It is now possible to use a character vector the function name (in addition to function objects) in all <code>FUN_*</code> arguments of the following functions: <code>Calibration()</code>, <code>Calibration_Michel()</code>, <code>CreateCalibOptions()</code>, <code>CreateIniStates()</code>, <code>CreateIniStates()</code>, <code>CreateInputsCrit()</code>, <code>CreateInputsModel()</code>, <code>CreateRunOptions()</code>, <code>ErrorCrit()</code>, <code>RunModel()</code> and <code>TransfoParam()</code>. + #### Minor user-visible changes diff --git a/R/Calibration.R b/R/Calibration.R index 162fd7d7..6c6f4980 100644 --- a/R/Calibration.R +++ b/R/Calibration.R @@ -1,9 +1,10 @@ Calibration <- function(InputsModel, RunOptions, InputsCrit, CalibOptions, FUN_MOD, FUN_CRIT, FUN_CALIB = Calibration_Michel, FUN_TRANSFO = NULL, verbose = TRUE) { - if (! is.function(FUN_CALIB)) { - stop("'FUN_CALIB' must be a function") - } + FUN_MOD <- match.fun(FUN_MOD) + FUN_CRIT <- match.fun(FUN_CRIT) + FUN_CALIB <- match.fun(FUN_CALIB) + FUN_TRANSFO <- match.fun(FUN_TRANSFO) return(FUN_CALIB(InputsModel, RunOptions, InputsCrit, CalibOptions, FUN_MOD, FUN_CRIT, FUN_TRANSFO, verbose = verbose)) } diff --git a/R/Calibration_Michel.R b/R/Calibration_Michel.R index 7649d722..8448ab52 100644 --- a/R/Calibration_Michel.R +++ b/R/Calibration_Michel.R @@ -2,6 +2,13 @@ Calibration_Michel <- function(InputsModel, RunOptions, InputsCrit, CalibOptions FUN_MOD, FUN_CRIT, FUN_TRANSFO = NULL, verbose = TRUE) { + FUN_MOD <- match.fun(FUN_MOD) + FUN_CRIT <- match.fun(FUN_CRIT) + if (!is.null(FUN_TRANSFO)) { + FUN_TRANSFO <- match.fun(FUN_TRANSFO) + } + + ##_____Arguments_check_____________________________________________________________________ if (!inherits(InputsModel, "InputsModel")) { stop("InputsModel must be of class 'InputsModel'") diff --git a/R/CreateCalibOptions.R b/R/CreateCalibOptions.R index cc09f8c0..944d6360 100644 --- a/R/CreateCalibOptions.R +++ b/R/CreateCalibOptions.R @@ -1,14 +1,16 @@ -CreateCalibOptions <- - function(FUN_MOD, - FUN_CALIB = Calibration_Michel, - FUN_TRANSFO = NULL, - FixedParam = NULL, - SearchRanges = NULL, - StartParamList = NULL, - StartParamDistrib = NULL) { - - ObjectClass <- NULL +CreateCalibOptions <- function(FUN_MOD, + FUN_CALIB = Calibration_Michel, + FUN_TRANSFO = NULL, + FixedParam = NULL, + SearchRanges = NULL, + StartParamList = NULL, + StartParamDistrib = NULL) { + + ObjectClass <- NULL + FUN_MOD <- match.fun(FUN_MOD) + FUN_CALIB <- match.fun(FUN_CALIB) + FUN_TRANSFO <- match.fun(FUN_TRANSFO) ##check_FUN_MOD BOOL <- FALSE diff --git a/R/CreateIniStates.R b/R/CreateIniStates.R index 92e57660..234802e7 100644 --- a/R/CreateIniStates.R +++ b/R/CreateIniStates.R @@ -11,6 +11,7 @@ CreateIniStates <- function(FUN_MOD, InputsModel, UH1n <- 20L UH2n <- UH1n * 2L + FUN_MOD <- match.fun(FUN_MOD) ## check FUN_MOD BOOL <- FALSE diff --git a/R/CreateInputsCrit.R b/R/CreateInputsCrit.R index 3d98d517..ea37616f 100644 --- a/R/CreateInputsCrit.R +++ b/R/CreateInputsCrit.R @@ -15,6 +15,8 @@ CreateInputsCrit <- function(FUN_CRIT, ObjectClass <- NULL + FUN_CRIT <- match.fun(FUN_CRIT) + ## ---------- check arguments if (!missing(Qobs)) { diff --git a/R/CreateInputsModel.R b/R/CreateInputsModel.R index 6597dae4..b99a10ec 100644 --- a/R/CreateInputsModel.R +++ b/R/CreateInputsModel.R @@ -9,6 +9,8 @@ CreateInputsModel <- function(FUN_MOD, ObjectClass <- NULL + FUN_MOD <- match.fun(FUN_MOD) + ##check_FUN_MOD BOOL <- FALSE if (identical(FUN_MOD, RunModel_GR4H)) { diff --git a/R/CreateRunOptions.R b/R/CreateRunOptions.R index 753ed319..5cc017f3 100644 --- a/R/CreateRunOptions.R +++ b/R/CreateRunOptions.R @@ -10,6 +10,8 @@ CreateRunOptions <- function(FUN_MOD, InputsModel, IndPeriod_WarmUp = NULL, IndP ObjectClass <- NULL + FUN_MOD <- match.fun(FUN_MOD) + ##check_FUN_MOD BOOL <- FALSE; if (identical(FUN_MOD, RunModel_GR4H)) { diff --git a/R/ErrorCrit.R b/R/ErrorCrit.R index a84230a6..a0f5b8cb 100644 --- a/R/ErrorCrit.R +++ b/R/ErrorCrit.R @@ -1,5 +1,7 @@ ErrorCrit <- function(InputsCrit, OutputsModel, FUN_CRIT, warnings = TRUE, verbose = TRUE) { + FUN_CRIT <- match.fun(FUN_CRIT) + ## ---------- Arguments check if (!inherits(InputsCrit, "InputsCrit")) { diff --git a/R/RunModel.R b/R/RunModel.R index a561c1b4..80d6b370 100644 --- a/R/RunModel.R +++ b/R/RunModel.R @@ -1,3 +1,4 @@ RunModel <- function(InputsModel, RunOptions, Param, FUN_MOD) { + FUN_MOD <- match.fun(FUN_MOD) return(FUN_MOD(InputsModel, RunOptions, Param)) } diff --git a/R/TransfoParam.R b/R/TransfoParam.R index fcc5368f..dcda7b08 100644 --- a/R/TransfoParam.R +++ b/R/TransfoParam.R @@ -1,3 +1,4 @@ TransfoParam <- function(ParamIn, Direction, FUN_TRANSFO) { + FUN_TRANSFO <- match.fun(FUN_TRANSFO) return(FUN_TRANSFO(ParamIn, Direction)) } -- GitLab