From 98cbf01a1627777719a8ff7ea5e73705894c5945 Mon Sep 17 00:00:00 2001
From: Delaigue Olivier <olivier.delaigue@irstea.fr>
Date: Tue, 8 Feb 2022 16:30:35 +0100
Subject: [PATCH] fix(airGRteaching): temporarily restore the deprecated
 FUN_CRIT argument in Calibration and Calibration_Michel - to avoid error on
 CRAN version of airGRteaching Refs #81, #146

---
 R/Calibration.R           | 5 +++++
 R/Calibration_Michel.R    | 9 +++++++++
 man/Calibration.Rd        | 4 +++-
 man/Calibration_Michel.Rd | 4 +++-
 4 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/R/Calibration.R b/R/Calibration.R
index 3cce7b36..d526294f 100644
--- a/R/Calibration.R
+++ b/R/Calibration.R
@@ -3,6 +3,7 @@ Calibration <- function(InputsModel,
                         InputsCrit,
                         CalibOptions,
                         FUN_MOD,
+                        FUN_CRIT,                      # deprecated
                         FUN_CALIB = Calibration_Michel,
                         FUN_TRANSFO = NULL,
                         verbose = TRUE,
@@ -10,6 +11,10 @@ Calibration <- function(InputsModel,
 
   FUN_MOD   <- match.fun(FUN_MOD)
 
+  if (!missing(FUN_CRIT)) {
+    FUN_CRIT <- match.fun(FUN_CRIT)
+  }
+
   FUN_CALIB <- match.fun(FUN_CALIB)
 
   if (!is.null(FUN_TRANSFO)) {
diff --git a/R/Calibration_Michel.R b/R/Calibration_Michel.R
index 854ab723..4a60a4ca 100644
--- a/R/Calibration_Michel.R
+++ b/R/Calibration_Michel.R
@@ -3,6 +3,7 @@ Calibration_Michel <- function(InputsModel,
                                InputsCrit,
                                CalibOptions,
                                FUN_MOD,
+                               FUN_CRIT,           # deprecated
                                FUN_TRANSFO = NULL,
                                verbose = TRUE,
                                ...) {
@@ -10,6 +11,10 @@ Calibration_Michel <- function(InputsModel,
 
   FUN_MOD  <- match.fun(FUN_MOD)
 
+  if (!missing(FUN_CRIT)) {
+    FUN_CRIT <- match.fun(FUN_CRIT)
+  }
+
   # Handling 'FUN_TRANSFO' from direct argument or provided by 'CaliOptions'
   if (!is.null(FUN_TRANSFO)) {
     FUN_TRANSFO <- match.fun(FUN_TRANSFO)
@@ -52,6 +57,10 @@ Calibration_Michel <- function(InputsModel,
   if (!inherits(CalibOptions, "HBAN")) {
     stop("'CalibOptions' must be of class 'HBAN' if 'Calibration_Michel' is used")
   }
+  if (!missing(FUN_CRIT)) {
+    warning("argument 'FUN_CRIT' is deprecated. The error criterion function is now automatically get from the 'InputsCrit' object")
+  }
+
 
   ##_variables_initialisation
   ParamFinalR <- NULL
diff --git a/man/Calibration.Rd b/man/Calibration.Rd
index 65d8ee7a..f6a7637e 100644
--- a/man/Calibration.Rd
+++ b/man/Calibration.Rd
@@ -15,7 +15,7 @@ Calibration algorithm that optimises the error criterion selected as objective f
 
 \usage{
 Calibration(InputsModel, RunOptions, InputsCrit, CalibOptions,
-            FUN_MOD, FUN_CALIB = Calibration_Michel,
+            FUN_MOD, FUN_CRIT, FUN_CALIB = Calibration_Michel,
             FUN_TRANSFO = NULL, verbose = TRUE, ...)
 }
 
@@ -31,6 +31,8 @@ Calibration(InputsModel, RunOptions, InputsCrit, CalibOptions,
 
 \item{FUN_MOD}{[function] hydrological model function (e.g. \code{\link{RunModel_GR4J}}, \code{\link{RunModel_CemaNeigeGR4J}})}
 
+\item{FUN_CRIT}{(deprecated) [function] error criterion function (e.g. \code{\link{ErrorCrit_RMSE}}, \code{\link{ErrorCrit_NSE}})}
+
 \item{FUN_CALIB}{(deprecated) [function] calibration algorithm function (e.g. \code{\link{Calibration_Michel}}), \code{default = Calibration_Michel}}
 
 \item{FUN_TRANSFO}{(optional) [function] model parameters transformation function, if the \code{FUN_MOD} used is native in the package \code{FUN_TRANSFO} is automatically defined}
diff --git a/man/Calibration_Michel.Rd b/man/Calibration_Michel.Rd
index 6befd8b0..28de8c44 100644
--- a/man/Calibration_Michel.Rd
+++ b/man/Calibration_Michel.Rd
@@ -19,7 +19,7 @@ Then a steepest descent local search algorithm is performed, starting from the r
 
 \usage{
 Calibration_Michel(InputsModel, RunOptions, InputsCrit, CalibOptions,
-                   FUN_MOD, FUN_TRANSFO = NULL, verbose = TRUE, ...)
+                   FUN_MOD, FUN_CRIT, FUN_TRANSFO = NULL, verbose = TRUE, ...)
 }
 
 
@@ -34,6 +34,8 @@ Calibration_Michel(InputsModel, RunOptions, InputsCrit, CalibOptions,
 
 \item{FUN_MOD}{[function] hydrological model function (e.g. \code{\link{RunModel_GR4J}}, \code{\link{RunModel_CemaNeigeGR4J}})}
 
+\item{FUN_CRIT}{(deprecated) [function] error criterion function (e.g. \code{\link{ErrorCrit_RMSE}}, \code{\link{ErrorCrit_NSE}})}
+
 \item{FUN_TRANSFO}{(optional) [function] model parameters transformation function, if the \code{FUN_MOD} used is native in the package \code{FUN_TRANSFO} is automatically defined}
 
 \item{verbose}{(optional) [boolean] boolean indicating if the function is run in verbose mode or not, default = \code{TRUE}}
-- 
GitLab