From 8512d310eeca1b935aa7d4d77d0492fdee4dfbc1 Mon Sep 17 00:00:00 2001 From: Delaigue Olivier <olivier.delaigue@irstea.priv> Date: Wed, 17 Apr 2019 10:09:13 +0200 Subject: [PATCH] v1.2.14.7 BUG: missing inputs and outputs added in .ErrorCrit fun --- DESCRIPTION | 4 ++-- NEWS.rmd | 2 +- R/Utils.R | 30 ++++++++++++++++-------------- 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 329a7257..46160487 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Package: airGR Type: Package Title: Suite of GR Hydrological Models for Precipitation-Runoff Modelling -Version: 1.2.14.6 -Date: 2019-04-16 +Version: 1.2.14.7 +Date: 2019-04-17 Authors@R: c( person("Laurent", "Coron", role = c("aut", "trl"), comment = c(ORCID = "0000-0002-1503-6204")), person("Olivier", "Delaigue", role = c("aut", "cre"), comment = c(ORCID = "0000-0002-7668-8468"), email = "airGR@irstea.fr"), diff --git a/NEWS.rmd b/NEWS.rmd index 409a0708..df2706e1 100644 --- a/NEWS.rmd +++ b/NEWS.rmd @@ -14,7 +14,7 @@ output: -### 1.2.14.6 Release Notes (2019-04-16) +### 1.2.14.7 Release Notes (2019-04-17) #### New features diff --git a/R/Utils.R b/R/Utils.R index 69fe7901..268074a5 100644 --- a/R/Utils.R +++ b/R/Utils.R @@ -81,17 +81,17 @@ ## function to manage inputs of specific ErrorCrit_*() functions ## ================================================================================= -.ErrorCrit <- function(InputsCrit, crit) { +.ErrorCrit <- function(InputsCrit, Crit, OutputsModel, warnings) { ## Arguments check if (!inherits(InputsCrit, "InputsCrit")) { stop("'InputsCrit' must be of class 'InputsCrit'", call. = FALSE) } if (inherits(InputsCrit, "Multi") | inherits(InputsCrit, "Compo")) { - if (crit == "RMSE") { + if (Crit == "RMSE") { stop("'InputsCrit' must be of class 'Single'. Use the 'ErrorCrit' function on objects of class 'Multi' with RMSE", call. = FALSE) } else { - stop(paste0("'InputsCrit' must be of class 'Single'. Use the 'ErrorCrit' function on objects of class 'Multi' or 'Compo' with ", crit), call. = FALSE) + stop(paste0("'InputsCrit' must be of class 'Single'. Use the 'ErrorCrit' function on objects of class 'Multi' or 'Compo' with ", Crit), call. = FALSE) } } @@ -100,25 +100,25 @@ CritName <- NA CritVar <- InputsCrit$VarObs if (InputsCrit$transfo == "") { - CritName <- paste0(crit, "[CritVar]") + CritName <- paste0(Crit, "[CritVar]") } if (InputsCrit$transfo %in% c("sqrt", "log", "sort")) { - CritName <- paste0(crit, "[", InputsCrit$transfo, "(CritVar)]") + CritName <- paste0(Crit, "[", InputsCrit$transfo, "(CritVar)]") } if (InputsCrit$transfo == "inv") { - CritName <- paste0(crit, "[1/CritVar]") + CritName <- paste0(Crit, "[1/CritVar]") } - if (grepl("^", InputsCrit$transfo)) { - transfoPow <- as.numeric(gsub("^", "", InputsCrit$transfo)) - CritName <- paste0(crit, "[CritVar^", transfoPow, "]") + if (grepl("\\^", InputsCrit$transfo)) { + transfoPow <- suppressWarnings(as.numeric(gsub("\\^", "", InputsCrit$transfo))) + CritName <- paste0(Crit, "[CritVar^", transfoPow, "]") } CritName <- gsub(pattern = "CritVar", replacement = CritVar, x = CritName) CritValue <- NA - if (crit %in% c("RMSE")) { + if (Crit %in% c("RMSE")) { CritBestValue <- +1 Multiplier <- +1 } - if (crit %in% c("NSE", "KGE", "KGE2")) { + if (Crit %in% c("NSE", "KGE", "KGE2")) { CritBestValue <- +1 Multiplier <- -1 } @@ -172,7 +172,7 @@ VarObs <- sort(VarObs, na.last = TRUE) InputsCrit$BoolCrit <- sort(InputsCrit$BoolCrit, decreasing = TRUE) } - if ("exp" %in% InputsCrit$transfo) { + if (grepl("\\^", InputsCrit$transfo)) { VarObs <- VarObs^transfoPow VarSim <- VarSim^transfoPow } @@ -184,7 +184,7 @@ if (length(Ind_TS_ignore) == 0) { Ind_TS_ignore <- NULL } - if (sum(!TS_ignore) == 0 | (sum(!TS_ignore) == 1 & crit %in% c("KGE", "KGE2"))) { + if (sum(!TS_ignore) == 0 | (sum(!TS_ignore) == 1 & Crit %in% c("KGE", "KGE2"))) { CritCompute <- FALSE } else { CritCompute <- TRUE @@ -214,7 +214,9 @@ Multiplier = Multiplier, CritName = CritName, CritVar = CritVar, - CritCompute = CritCompute) + CritCompute = CritCompute, + TS_ignore = TS_ignore, + Ind_TS_ignore = Ind_TS_ignore) } -- GitLab