From f7dc34d554cde7ad840b9e4b747291a788f2b613 Mon Sep 17 00:00:00 2001
From: Delaigue Olivier <olivier.delaigue@irstea.priv>
Date: Wed, 6 Mar 2019 14:37:16 +0100
Subject: [PATCH] v1.2.8.5 BUG: Calibration_Michel can manage with single or
 compo InputsCrit to check needed missing outputs in RunOptions when SCA or
 SWE is used

---
 DESCRIPTION            |  2 +-
 NEWS.rmd               |  2 +-
 R/Calibration_Michel.R | 10 ++++++++--
 3 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/DESCRIPTION b/DESCRIPTION
index 6e64317f..84122143 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.4
+Version: 1.2.8.5
 Date: 2019-03-06
 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 cfd6b906..ee266975 100644
--- a/NEWS.rmd
+++ b/NEWS.rmd
@@ -13,7 +13,7 @@ output:
 
 
 
-### 1.2.8.4 Release Notes (2019-03-06) 
+### 1.2.8.5 Release Notes (2019-03-06) 
 
 
 
diff --git a/R/Calibration_Michel.R b/R/Calibration_Michel.R
index 65948136..7649d722 100644
--- a/R/Calibration_Michel.R
+++ b/R/Calibration_Michel.R
@@ -15,11 +15,17 @@ Calibration_Michel <- function(InputsModel, RunOptions, InputsCrit, CalibOptions
   if (inherits(InputsCrit, "Multi")) {
     stop("InputsCrit must be of class 'Single' or 'Compo'")
   }
-  if (inherits(InputsCrit, "Compo") & "SCA" %in% sapply(InputsCrit, "[[", "varObs") & !"Gratio" %in% RunOptions$Outputs_Cal) {
+  if (inherits(InputsCrit, "Single")) {
+    listVarObs <- InputsCrit$varObs
+  }
+  if (inherits(InputsCrit, "Compo")) {
+    listVarObs <- sapply(InputsCrit, FUN = "[[", "varObs")
+  }
+  if ("SCA" %in% listVarObs & !"Gratio" %in% RunOptions$Outputs_Cal) {
     warning("Missing 'Gratio' is automatically added to 'Output_Cal' in 'RunOptions' as it is necessary in the objective function for comparison with SCA")
     RunOptions$Outputs_Cal <- c(RunOptions$Outputs_Cal, "Gratio")
   }
-  if (inherits(InputsCrit, "Compo") & "SWE" %in% sapply(InputsCrit, "[[", "varObs") & !"SnowPack" %in% RunOptions$Outputs_Cal) {
+  if ("SWE" %in% listVarObs & !"SnowPack" %in% RunOptions$Outputs_Cal) {
     warning("Missing 'SnowPack' is automatically added to 'Output_Cal' in 'RunOptions' as it is necessary in the objective function for comparison with SWE")
     RunOptions$Outputs_Cal <- c(RunOptions$Outputs_Cal, "SnowPack")
   }
-- 
GitLab