Skip to content

Commit

Permalink
Add parameter to 'construct.ranges' to construct cumulative ranges
Browse files Browse the repository at this point in the history
Works towards se-sic#265.

Signed-off-by: Maximilian Löffler <[email protected]>
  • Loading branch information
maxloeffler committed Sep 12, 2024
1 parent 0c2f47c commit a135f6b
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions util-misc.R
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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 ranges
if ((offset + 1) <= length(revs)) {
seq2 = revs[ (offset + 1):length(revs) ]
} else {
Expand Down

0 comments on commit a135f6b

Please sign in to comment.