From 64897b4a4585f79154ab6812601c4aec78b9fe62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20L=C3=B6ffler?= Date: Tue, 3 Sep 2024 18:08:28 +0200 Subject: [PATCH] Add parameter to 'construct.ranges' to construct cumulative ranges MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Works towards #265. Signed-off-by: Maximilian Löffler --- util-misc.R | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/util-misc.R b/util-misc.R index 03f07420..aac0b260 100644 --- a/util-misc.R +++ b/util-misc.R @@ -522,12 +522,13 @@ get.time.period.by.amount = function(start.date, end.date, amount) { #' @param revs the revisions #' @param sliding.window whether sliding window splitting is enabled or not #' [default: FALSE] +#' @param cumulative whether to construct cumulative ranges [default: FALSE] #' @param raw whether to return pairs of POSIXct objects or strings rather than #' formatted strings [default: FALSE] #' #' @return the constructed ranges, either formatted or raw; the raw ranges are a named list, #' for which the formatted ranges are the names -construct.ranges = function(revs, sliding.window = FALSE, raw = FALSE) { +construct.ranges = function(revs, sliding.window = FALSE, cumulative = FALSE, raw = FALSE) { ## make sure that, at least, two revisions are provided if (length(revs) < 2) { @@ -544,8 +545,14 @@ construct.ranges = function(revs, sliding.window = FALSE, raw = FALSE) { if (sliding.window) offset = 2 - ## extract sequences of revisions - seq1 = revs[ 1:(length(revs) - offset) ] + ## extract start of ranges + if (cumulative) { + seq1 = rep(revs[1], length(revs) - offset) + } else { + seq1 = revs[ 1:(length(revs) - offset) ] + } + + ## extract end of reanges if ((offset + 1) <= length(revs)) { seq2 = revs[ (offset + 1):length(revs) ] } else {