diff --git a/DESCRIPTION b/DESCRIPTION index 6af3f94b416e5dcf383cdff278cf08e8676f136e..67edaf4e9b4f3a67d5767765384f19687f0f6799 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.6.8.34 +Version: 1.6.8.35 Date: 2021-01-05 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 f377f10d4e0e5ede5e2a7d8a3ee842e12d5434e8..2517a356f14436c12717fdbae10f4cc0404b15ea 100644 --- a/NEWS.md +++ b/NEWS.md @@ -7,7 +7,7 @@ #### 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 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>.GetAggregConvertFun()</code> private function in order to choose automatically the <code>ConvertFun</code> to apply on each element of objects used in <code>SeriesAggreg.InputsModel</code> and <code>SeriesAggreg.OutputsModel</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. #### Bug fixes diff --git a/R/SeriesAggreg.InputsModel.R b/R/SeriesAggreg.InputsModel.R index 9902fb97dea8f00db7286737722c41a3437b8d03..a6414fb823235d3fb19904602adcd8a177b82466 100644 --- a/R/SeriesAggreg.InputsModel.R +++ b/R/SeriesAggreg.InputsModel.R @@ -1,6 +1,6 @@ SeriesAggreg.InputsModel <- function(x, ...) { SeriesAggreg.list(x, - ConvertFun = getAggregConvertFun(names(x)), + ConvertFun = .GetAggregConvertFun(names(x)), except = c("ZLayers", "LengthHydro", "BasinAreas"), ...) } diff --git a/R/SeriesAggreg.OutputsModel.R b/R/SeriesAggreg.OutputsModel.R index ad680452168344d573522fbb3dbf56a068be9c8a..264bd5b7fb7f41e226004ce244d545246eefe881 100644 --- a/R/SeriesAggreg.OutputsModel.R +++ b/R/SeriesAggreg.OutputsModel.R @@ -1,6 +1,6 @@ SeriesAggreg.OutputsModel <- function(x, ...) { SeriesAggreg.list(x, - ConvertFun = getAggregConvertFun(names(x)), + ConvertFun = .GetAggregConvertFun(names(x)), except = "StateEnd", ...) } diff --git a/R/SeriesAggreg.data.frame.R b/R/SeriesAggreg.data.frame.R index fd97145bf0994bdbaf5dba0f45163f002f65714c..68f2d625382d175a4c406e0cc44621ceb729270a 100644 --- a/R/SeriesAggreg.data.frame.R +++ b/R/SeriesAggreg.data.frame.R @@ -11,7 +11,7 @@ SeriesAggreg.data.frame <- function(x, warning("deprecated 'TimeFormat' argument", call. = FALSE) } if (missing(Format)) { - Format <- getSeriesAggregFormat(NewTimeFormat) + Format <- .GetSeriesAggregFormat(NewTimeFormat) } else if (!is.null(NewTimeFormat)) { warning("deprecated 'NewTimeFormat' argument: 'Format' argument is used instead", call. = FALSE) diff --git a/R/SeriesAggreg.list.R b/R/SeriesAggreg.list.R index c075167b8cd15395c31f469b117c46615d99d087..8834347dbc5ac40fa35a5c19b074699173c34f15 100644 --- a/R/SeriesAggreg.list.R +++ b/R/SeriesAggreg.list.R @@ -7,7 +7,7 @@ SeriesAggreg.list <- function(x, recursive = TRUE, ...) { if (missing(Format)) { - Format <- getSeriesAggregFormat(NewTimeFormat) + Format <- .GetSeriesAggregFormat(NewTimeFormat) } else if (!is.null(NewTimeFormat)) { warning("deprecated 'NewTimeFormat' argument: 'Format' argument is used instead", call. = FALSE) @@ -59,7 +59,7 @@ SeriesAggreg.list <- function(x, } dfOut <- NULL if (length(cols)) { - ConvertFun2 <- getAggregConvertFun(names(cols)) + ConvertFun2 <- .GetAggregConvertFun(names(cols)) if (is.null(recursive)) { if (missing(ConvertFun)) { stop("'ConvertFun' argument should provided if 'recursive = NULL'") @@ -94,7 +94,7 @@ SeriesAggreg.list <- function(x, listCols <- listCols[setdiff(names(listCols), names(dfCols))] if (length(listCols) > 0) { # Check for predefined ConvertFun for all sub-elements - ConvertFun <- getAggregConvertFun(names(listCols)) + ConvertFun <- .GetAggregConvertFun(names(listCols)) # Run SeriesAggreg for each embedded list listRes <- lapply(names(listCols), function(x) { listCols[[x]]$DatesR <- DatesR @@ -129,7 +129,7 @@ SeriesAggreg.list <- function(x, "), it will be ignored in the aggregation" ) } else { - ConvertFun <- rep(getAggregConvertFun(key), ncol(m)) + ConvertFun <- rep(.GetAggregConvertFun(key), ncol(m)) res[[key]] <- SeriesAggreg(data.frame(DatesR, m), Format = Format, ConvertFun = ConvertFun) @@ -142,7 +142,7 @@ SeriesAggreg.list <- function(x, res <- c(res, x[setdiff(names(x), names(res))]) class(res) <- gsub("hourly|daily|monthly|yearly", - getSeriesAggregClass(Format), + .GetSeriesAggregClass(Format), class(x)) return(res) diff --git a/R/UtilsSeriesAggreg.R b/R/UtilsSeriesAggreg.R index bb371746d2798a653eb7feca5721d89f439e3bed..94d7e181b9e4e37cc9c2fffc9d478b94c464348d 100644 --- a/R/UtilsSeriesAggreg.R +++ b/R/UtilsSeriesAggreg.R @@ -1,4 +1,4 @@ -getSeriesAggregFormat <- function(NewTimeFormat) { +.GetSeriesAggregFormat <- function(NewTimeFormat) { errNewTimeFormat <- FALSE if (missing(NewTimeFormat)) { errNewTimeFormat <- TRUE @@ -25,7 +25,7 @@ getSeriesAggregFormat <- function(NewTimeFormat) { return(NULL) } -getSeriesAggregClass <- function(Format) { +.GetSeriesAggregClass <- function(Format) { Format <- substr(Format, start = nchar(Format), stop = nchar(Format)) @@ -36,18 +36,18 @@ getSeriesAggregClass <- function(Format) { Y = "yearly") } -getAggregConvertFun <- function(Outputs) { +.GetAggregConvertFun <- function(Outputs) { AggregConvertFunTable <- rbind( data.frame(ConvertFun = "mean", Outputs = c("Prod","Rout","Exp","SnowPack","ThermalState", "Gratio","Temp","Gthreshold","Glocalmax","LayerTempMean", "T"), - stringsAsFactors = FALSE), # R < 4.0 compatibility: avoids mixing numeric and factor into numeric in getAggregConvertFun() + stringsAsFactors = FALSE), # R < 4.0 compatibility: avoids mixing numeric and factor into numeric data.frame(ConvertFun = "sum", Outputs = c("PotEvap","Precip","Pn","Ps","AE","Perc","PR","Q9", "Q1","Exch","AExch1","AExch2","AExch","QR","QRExp", "QD","Qsim","Pliq","Psol","PotMelt","Melt","PliqAndMelt", "LayerPrecip","LayerFracSolidPrecip", "Qmm", "Qls", "E", "P", "Qupstream"), - stringsAsFactors = FALSE) # R < 4.0 compatibility: avoids mixing numeric and factor into numeric in getAggregConvertFun() + stringsAsFactors = FALSE) # R < 4.0 compatibility: avoids mixing numeric and factor into numeric ) res <- sapply(Outputs, function(iOutputs) { iRes <- AggregConvertFunTable$ConvertFun[AggregConvertFunTable$Outputs == iOutputs] diff --git a/man/SeriesAggreg.Rd b/man/SeriesAggreg.Rd index 41d4a8a341b24ebaad551e80942a3b392fb7b0b9..2c095b545f4e10a5fb985e31a4e55c35fec73d69 100644 --- a/man/SeriesAggreg.Rd +++ b/man/SeriesAggreg.Rd @@ -20,11 +20,14 @@ Warning: on the aggregated outputs, the dates correspond to the beginning of the (e.g. for yearly time series 2005-03-01 00:00 = value for period 2005-03-01 00:00 - 2006-02-28 23:59) } + \details{ \code{\link{SeriesAggreg.InputsModel}} and \code{\link{SeriesAggreg.OutputsModel}} call \code{\link{SeriesAggreg.list}} which itself calls \code{\link{SeriesAggreg.data.frame}}. So, all arguments passed to any \code{\link{SeriesAggreg}} method will be passed to \code{\link{SeriesAggreg.data.frame}}. } + + \usage{ \method{SeriesAggreg}{data.frame}(x, Format,