From 8f0ecd4fede6eb607a7de230d1eb807045eaab95 Mon Sep 17 00:00:00 2001
From: Delaigue Olivier <olivier.delaigue@irstea.priv>
Date: Fri, 7 Jun 2019 11:26:33 +0200
Subject: [PATCH] v1.2.16.29 CLEAN: warning msg management improved in
 plot.OutputsModel fun

---
 DESCRIPTION           |  2 +-
 NEWS.rmd              |  2 +-
 R/plot.OutputsModel.R | 24 +++++++++++-------------
 3 files changed, 13 insertions(+), 15 deletions(-)

diff --git a/DESCRIPTION b/DESCRIPTION
index 7bfe3927..5cb8621c 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.16.28
+Version: 1.2.16.29
 Date: 2019-06-07
 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 68cbb735..0c6143ca 100644
--- a/NEWS.rmd
+++ b/NEWS.rmd
@@ -14,7 +14,7 @@ output:
 
 
 
-### 1.2.16.28 Release Notes (2019-06-07)
+### 1.2.16.29 Release Notes (2019-06-07)
 
 
 #### New features
diff --git a/R/plot.OutputsModel.R b/R/plot.OutputsModel.R
index f5b06900..a14c1d7c 100644
--- a/R/plot.OutputsModel.R
+++ b/R/plot.OutputsModel.R
@@ -77,7 +77,10 @@ plot.OutputsModel <- function(x, Qobs = NULL, IndPeriod_Plot = NULL, BasinArea =
   whichTS    <- c("Precip", "PotEvap", "Temp", "SnowPack", "Flows"                                       )
   whichPerf  <- c(                                                  "Error", "Regime", "CumFreq", "CorQQ")
   whichCN    <- c(                     "Temp", "SnowPack"                                                )
-  warnMsgWhich <- "'which' must be a vector of character"
+  warnMsgWhich   <- "'which' must be a vector of character"
+  warnMsgWhichCN <- sprintf("incorrect element found in argument 'which':\n\twithout CemaNeige, %s are not available \n\tit can only contain %s",
+                            paste0(shQuote(whichCN), collapse = " and "),
+                            paste0(shQuote(c(whichDashboard, whichAll[!whichAll %in% whichCN])), collapse = ", "))
   if (is.null(which)) {
     stop(warnMsgWhich)
   }
@@ -88,21 +91,15 @@ plot.OutputsModel <- function(x, Qobs = NULL, IndPeriod_Plot = NULL, BasinArea =
     stop(warnMsgWhich)
   }
   if (any(!which %in% c(whichDashboard, whichAll))) {
-    stop("incorrect element found in argument 'which': ",  paste0(shQuote(which[!which %in% c(whichDashboard, whichAll)])),
-         "\nit can only contain ",
-         paste0(shQuote(c(whichDashboard, whichAll)), collapse = ", "))
+    stop(sprintf("incorrect element found in argument 'which': %s\nit can only contain %s",
+                 paste0(shQuote(which[!which %in% c(whichDashboard, whichAll)])),
+                 paste0(shQuote(c(whichDashboard, whichAll)), collapse = ", ")))
   }
   if (all(which %in% whichCN) & !inherits(OutputsModel, "CemaNeige")) {
-    stop("incorrect element found in argument 'which':",
-         "\n\twithout CemaNeige, ", paste0(shQuote(whichCN), collapse = " and "), " are not available",
-         "\n\tit can only contain ",
-         paste0(shQuote(c(whichDashboard, whichAll[!whichAll %in% whichCN])), collapse = ", "))
+    stop(warnMsgWhichCN)
   }
   if (length(unique(which %in% whichCN)) == 2 & !inherits(OutputsModel, "CemaNeige")) {
-    warning("incorrect element found in argument 'which':",
-            "\n\twithout CemaNeige, ", paste0(shQuote(whichCN), collapse = " and "), " are not available",
-            "\n\tit can only contain ",
-            paste0(shQuote(c(whichDashboard, whichAll[!whichAll %in% whichCN])), collapse = ", "))
+    warning(warnMsgWhichCN)
   }
   if ("perf" %in% which) {
     which <- c(which, whichPerf)
@@ -118,7 +115,8 @@ plot.OutputsModel <- function(x, Qobs = NULL, IndPeriod_Plot = NULL, BasinArea =
   }
   if (is.null(Qobs)) {
     if (length(which) == 1 & any(which %in% whichNeedQobs)) {
-      stop(sprintf("the %s plot(s) cannot be drawn if there is no 'Qobs'", shQuote(which)))
+      stop(sprintf("the %s plot(s) cannot be drawn if there is no 'Qobs'",
+                   shQuote(which)))
     }
     if (length(which) != 1 & any(which %in% whichNeedQobs)) {
       BOOL_CorQQ <- FALSE
-- 
GitLab