From 82e1cd7dbe58f80e689a8e270f5017dc11f6ac95 Mon Sep 17 00:00:00 2001 From: Delaigue Olivier <olivier.delaigue@irstea.fr> Date: Thu, 9 Apr 2020 20:02:09 +0200 Subject: [PATCH] v1.4.4.15 CLEAN: ConvertFun checked simplified in SeriesAggreg2 --- DESCRIPTION | 2 +- NEWS.md | 2 +- R/SeriesAggreg2.R | 12 ++++-------- 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 5ab57cb9..02d20cc4 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.4.4.14 +Version: 1.4.4.15 Date: 2020-04-09 Authors@R: c( person("Laurent", "Coron", role = c("aut", "trl"), comment = c(ORCID = "0000-0002-1503-6204")), diff --git a/NEWS.md b/NEWS.md index d7a4baa1..83d0ca96 100644 --- a/NEWS.md +++ b/NEWS.md @@ -4,7 +4,7 @@ -### 1.4.4.14 Release Notes (2020-04-09) +### 1.4.4.15 Release Notes (2020-04-09) #### New features diff --git a/R/SeriesAggreg2.R b/R/SeriesAggreg2.R index befb899c..6fbbffe6 100644 --- a/R/SeriesAggreg2.R +++ b/R/SeriesAggreg2.R @@ -28,20 +28,16 @@ SeriesAggreg2 <- function(TabSeries, Format, ConvertFun, Format <- gsub(pattern = "[[:punct:]]+", replacement = "%", Format) Format <- match.arg(Format, choices = listFormat) ## check ConvertFun - if (!is.vector(ConvertFun)) { - stop("'ConvertFun' must be a vector of character") - } - if (!is.character(ConvertFun)) { - stop("'ConvertFun' must be a vector of character") + listConvertFun <- c("sum", "mean") + ConvertFun <- listConvertFun[match(ConvertFun, listConvertFun)] + if (anyNA(ConvertFun)) { + stop("'ConvertFun' should be a one of 'sum' or 'mean'") } if (length(ConvertFun) != (ncol(TabSeries) - 1)) { stop( sprintf("'ConvertFun' must be of length %i (ncol(TabSeries)-1)", ncol(TabSeries) - 1) ) } - if (!all(ConvertFun %in% c("sum", "mean"))) { - stop("'ConvertFun' should be one of 'sum' or 'mean'") - } ## check YearFirstMonth msgYearFirstMonth <- "'YearFirstMonth' should be a numeric value between 1 and 12" YearFirstMonth <- match(YearFirstMonth, 1:12) -- GitLab