Commit 538bf8fc authored by Dorchies David's avatar Dorchies David
Browse files

v1.6.8.16 refactor: remove useless DatesR argument from SeriesAggreg.list

- the POSIXt dates should be in the list provided as TabSeries argument

Refs #41
parent 958511fb
Pipeline #17962 passed with stages
in 11 minutes and 8 seconds
Package: airGR
Type: Package
Title: Suite of GR Hydrological Models for Precipitation-Runoff Modelling
Version: 1.6.8.15
Version: 1.6.8.16
Date: 2020-11-30
Authors@R: c(
person("Laurent", "Coron", role = c("aut", "trl"), comment = c(ORCID = "0000-0002-1503-6204")),
......
......@@ -3,7 +3,6 @@ SeriesAggreg.list <- function(TabSeries,
ConvertFun,
NewTimeFormat = NULL,
simplify = FALSE,
DatesR = NULL,
except = NULL,
recursive = TRUE,
...) {
......@@ -18,54 +17,24 @@ SeriesAggreg.list <- function(TabSeries,
call. = FALSE)
}
# Determination of DateR
# 'DatesR' is explicitly provided by argument 'DatesR'
bDatesR <- !is.null(DatesR)
if (bDatesR) {
if (inherits(DatesR, "character")) {
DatesR <- DatesR[1]
if (!is.null(TabSeries[[DatesR]])) {
DatesR <- TabSeries[[DatesR]]
} else {
stop(
"The item selected by the argument 'DatesR'='",
DatesR,
"' should exist in 'TabSeries'"
)
}
} else {
if (!inherits(DatesR, "POSIXt")) {
stop("Argument 'DatesR' should be of class 'POSIXt' or 'character'")
}
}
}
# If available, we take 'DatesR' item in 'TabSeries'
if (is.null(DatesR)) {
if (!is.null(TabSeries$DatesR)) {
DatesR <- TabSeries$DatesR
}
}
# Auto-detection of POSIXt item in Tabseries
if (!is.null(DatesR)) {
if (!inherits(DatesR, "POSIXt")) {
stop("'DatesR' should be of class 'POSIXt'")
# Determination of DatesR
if (!is.null(TabSeries$DatesR)) {
if (!inherits(TabSeries$DatesR, "POSIXt")) {
stop("'TabSeries$DatesR' should be of class 'POSIXt'")
}
DatesR <- TabSeries$DatesR
} else {
# Auto-detection of POSIXt item in Tabseries
itemPOSIXt <-
which(sapply(TabSeries, function(x) {
inherits(x, "POSIXt")
}, simplify = TRUE))[1]
if (is.na(itemPOSIXt)) {
stop(
"One item of argument 'TabSeries' should be of class 'POSIXt' ",
"or the dates should be provided by the 'DatesR' argument"
)
"At least one item of argument 'TabSeries' should be of class 'POSIXt'")
}
warning(
"Item 'DatesR' not found in 'TabSeries' argument and no argument 'DatesR' ",
"provided. The item ",
"Item 'DatesR' not found in 'TabSeries' argument: the item ",
names(TabSeries)[itemPOSIXt],
" has been automatically chosen"
)
......@@ -139,10 +108,10 @@ SeriesAggreg.list <- function(TabSeries,
listRes <-
lapply(names(listCols),
function(x) {
listCols[[x]]$DatesR <- DatesR
SeriesAggreg(
listCols[[x]],
Format = Format,
DatesR = DatesR,
except = except,
ConvertFun = ConvertFun[x],
recursive = NULL,
......
......@@ -37,7 +37,6 @@ YearFirstMonth = 1, TimeLag = 0, \dots)
ConvertFun,
NewTimeFormat = NULL,
simplify = FALSE,
DatesR = NULL,
except = NULL,
recursive = TRUE,
\dots)
......@@ -65,8 +64,6 @@ YearFirstMonth = 1, TimeLag = 0, \dots)
\item{simplify}{(optional) [boolean] if set to \code{TRUE}, a \code{\link{data.frame}} is returned instead of a \code{\link{list}}. Embedded lists are then ignored. Default = \code{FALSE}}
\item{DatesR}{(optional) [POSIXt] with the vector of dates if the dates are not provided in the argument \code{TabSeries}.}
\item{except}{(optional) [character] the name of the items to skip in the aggregation (default: \code{NULL})}
\item{recursive}{(optional) [boolean] if set to \code{FALSE}, embedded lists and dataframes are not aggregated (Default \code{TRUE})}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment