diff --git a/DESCRIPTION b/DESCRIPTION index be8bb30e249d44308fd3235c696a6b99b19995e9..ec4d9af3cc20ff3f95bba005799f80a7a83e1f38 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.6.8.28 -Date: 2020-12-22 +Version: 1.6.8.29 +Date: 2020-12-23 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@inrae.fr"), diff --git a/NEWS.md b/NEWS.md index 5bf06c6e544164037b11b766dee98504cf03df0a..9d778a3640bb22dd6cea5b339621f1ff92140d3a 100644 --- a/NEWS.md +++ b/NEWS.md @@ -2,11 +2,11 @@ -### 1.6.8.28 Release Notes (2020-12-22) +### 1.6.8.29 Release Notes (2020-12-22) #### New features -- Added <code>SeriesAggreg</code> S3 method with functions for `InputsModel`, `OutputsModel`, `list`, `data.frame` class objects. This new version of the <code>SeriesAggreg()</code> function allows to compute regimes. +- Added <code>SeriesAggreg</code> S3 method with functions for `InputsModel`, `OutputsModel`, `list`, `data.frame` class objects. This new version of the <code>SeriesAggreg()</code> function also allows to compute regimes. ([#25](https://gitlab.irstea.fr/HYCAR-Hydro/airgr/-/issues/25)) - Added <code>getAggregConvertFun()</code> private function in order to choose automatically the <code>ConvertFun</code> to apply on each element of objects used in <code>SeriesAggreg</code>. - Added <code>.AggregConvertFunTable</code> data.frame that allows the user to see what names of list items or data.frame column names are guessed and eventually customise this correspondence table. diff --git a/R/SeriesAggreg.data.frame.R b/R/SeriesAggreg.data.frame.R index 3320e8f1625547b9cfb470e1fa81b6a7f1b84aae..ec34826f71d6e53fffd49726e4da6df05eb93853 100644 --- a/R/SeriesAggreg.data.frame.R +++ b/R/SeriesAggreg.data.frame.R @@ -99,19 +99,19 @@ SeriesAggreg.data.frame <- function(x, as.numeric(format(TabSeries2$DatesR[1L], format = "%Y")) - 1) stop <- sprintf("%i-12-31 00:00:00", as.numeric(format(TabSeries2$DatesR[nrow(TabSeries2)], format = "%Y")) + 1) - Ts <- format(diff(x[1:2, 1])) - if (gsub("[0-9]+ ", "", Ts) == "hours") { - by <- "hours" + unitTs <- format(diff(x[1:2, 1])) + if (gsub("[0-9]+ ", "", unitTs) == "hours") { + byTs <- "hours" } else { - if (gsub(" days$", "", Ts) == "1") { - by <- "days" + if (gsub(" days$", "", unitTs) == "1") { + byTs <- "days" } else { - by <- "months" + byTs <- "months" } } fakeTs <- data.frame(DatesR = seq(from = as.POSIXct(start, tz = "UTC"), to = as.POSIXct(stop , tz = "UTC"), - by = by) + TimeLag) + by = byTs) + TimeLag) TabSeries2 <- merge(fakeTs, TabSeries2, by = "DatesR", all.x = TRUE) } TabSeries2$DatesRini <- TabSeries2$DatesR %in% TabSeries0$DatesR diff --git a/R/UtilsSeriesAggreg.R b/R/UtilsSeriesAggreg.R index 3568125e1be31f2efc692e7ae0dad8f409bd55ed..7a0ef8b125d12036a0a10a4bc4a9cc7db098e7a6 100644 --- a/R/UtilsSeriesAggreg.R +++ b/R/UtilsSeriesAggreg.R @@ -1,9 +1,9 @@ getSeriesAggregFormat <- function(NewTimeFormat) { - errNewTimeFormat = FALSE + errNewTimeFormat <- FALSE if (missing(NewTimeFormat)) { - errNewTimeFormat = TRUE + errNewTimeFormat <- TRUE } else if (is.null(NewTimeFormat)) { - errNewTimeFormat = TRUE + errNewTimeFormat <- TRUE } if (errNewTimeFormat) { stop("Argument `Format` is missing") @@ -11,35 +11,29 @@ getSeriesAggregFormat <- function(NewTimeFormat) { if (!is.null(NewTimeFormat)) { TimeStep <- c("hourly", "daily", "monthly", "yearly") NewTimeFormat <- match.arg(NewTimeFormat, choices = TimeStep) - Format <- switch( - NewTimeFormat, - hourly = "%Y%m%d%h", - daily = "%Y%m%d", - monthly = "%Y%m", - yearly = "%Y" - ) - msgNewTimeFormat <- - sprintf(" 'Format' automatically set to %s", sQuote(Format)) - warning( - "deprecated 'NewTimeFormat' argument: please use 'Format' instead.", - msgNewTimeFormat, - call. = FALSE - ) + Format <- switch(NewTimeFormat, + hourly = "%Y%m%d%h", + daily = "%Y%m%d", + monthly = "%Y%m", + yearly = "%Y") + msgNewTimeFormat <- sprintf("'Format' automatically set to %s", sQuote(Format)) + warning("deprecated 'NewTimeFormat' argument: please use 'Format' instead.", + msgNewTimeFormat, + call. = FALSE) return(Format) } return(NULL) } getSeriesAggregClass <- function(Format) { - switch( - substr(Format, - start = nchar(Format), - stop = nchar(Format)), - h = "hourly", - d = "daily", - m = "monthly", - Y = "yearly" - ) + Format <- substr(Format, + start = nchar(Format), + stop = nchar(Format)) + switch(Format, + h = "hourly", + d = "daily", + m = "monthly", + Y = "yearly") } .AggregConvertFunTable <- rbind( @@ -58,7 +52,7 @@ getSeriesAggregClass <- function(Format) { getAggregConvertFun <- function(Outputs) { res <- sapply(Outputs, function(iOutputs) { iRes <- .AggregConvertFunTable$ConvertFun[.AggregConvertFunTable$Outputs == iOutputs] - iRes <- ifelse(any(is.na(iRes)), NA, iRes) # R < 4.0 compatibility + iRes <- ifelse(test = any(is.na(iRes)), yes = NA, no = iRes) # R < 4.0 compatibility }) return(res) }