From 2be91ef17ea21414b17f84ef43b5109cdfd125cc Mon Sep 17 00:00:00 2001
From: unknown <olivier.delaigue@ANPI1430.antony.irstea.priv>
Date: Thu, 8 Dec 2016 18:04:47 +0100
Subject: [PATCH] #4445 Coerce NLayers to be of integer type in
 CreateInputsModel

---
 R/CreateInputsModel.R | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/R/CreateInputsModel.R b/R/CreateInputsModel.R
index 6446cd2e..f11f1600 100644
--- a/R/CreateInputsModel.R
+++ b/R/CreateInputsModel.R
@@ -35,7 +35,7 @@ CreateInputsModel <- function(FUN_MOD,DatesR,Precip,PotEvap=NULL,TempMean=NULL,T
       BOOL <- TRUE
     }
     if(!BOOL) {
-      stop("incorrect FUN_MOD for use in CreateInputsModel \n")
+      stop("Incorrect FUN_MOD for use in CreateInputsModel \n")
       return(NULL)
     } 
 
@@ -87,7 +87,11 @@ CreateInputsModel <- function(FUN_MOD,DatesR,Precip,PotEvap=NULL,TempMean=NULL,T
       if(NLayers <= 0) {
         stop("NLayers must be a positive integer value \n")
         return(NULL)
-      } 
+      }
+      if(NLayers != as.integer(NLayers)) {
+        warning("Coerce NLayers to be of integer type (", NLayers, " => ", as.integer(NLayers), ")")
+        NLayers <- as.integer(NLayers)
+      }       
     }
 
 
@@ -108,14 +112,14 @@ CreateInputsModel <- function(FUN_MOD,DatesR,Precip,PotEvap=NULL,TempMean=NULL,T
       WTxt <- NULL;
       WTxt <- paste(WTxt,"\t Missing values are not allowed in InputsModel \n",sep="");
       Select <- (max(which(BOOL_NA))+1):length(BOOL_NA);
-      if(Select[1L]>Select[2L]) { stop(paste("time series could not be trunced since missing values were detected at the list time-step  \n",sep="")); return(NULL); }
+      if(Select[1L]>Select[2L]) { stop("Time series could not be trunced since missing values were detected at the list time-step"); return(NULL); }
       if("GR" %in% ObjectClass) {
         Precip <- Precip[Select];  PotEvap <- PotEvap[Select]; }
       if("CemaNeige" %in% ObjectClass) {
         Precip <- Precip[Select];  TempMean <- TempMean[Select]; if(!is.null(TempMin) & !is.null(TempMax)) { TempMin <- TempMin[Select]; TempMax <- TempMax[Select]; } }
       DatesR <- DatesR[Select];
-      WTxt <- paste(WTxt,"\t -> data were trunced to keep the most recent available time-steps \n",sep="");
-      WTxt <- paste(WTxt,"\t -> ",length(Select)," time-steps were kept \n",sep="");
+      WTxt <- paste(WTxt,"\t -> Data were trunced to keep the most recent available time-steps \n",sep="");
+      WTxt <- paste(WTxt,"\t -> ", length(Select), " time-steps were kept \n",sep="");
       if(!is.null(WTxt) & verbose) { warning(WTxt); }
     }
 
-- 
GitLab