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 3, 2024
1 parent b032bcc commit 86acadc
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 @@ -524,10 +524,11 @@ get.time.period.by.amount = function(start.date, end.date, amount) {
#' [default: FALSE]
#' @param raw whether to return pairs of POSIXct objects or strings rather than
#' formatted strings [default: FALSE]
#' @param construct.cumulative whether to construct cumulative ranges [default: FALSE]

This comment has been minimized.

Copy link
@bockthom

bockthom Sep 6, 2024

The param is just called "cumulative".

#'
#' @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, raw = FALSE, cumulative = FALSE) {

This comment has been minimized.

Copy link
@bockthom

bockthom Sep 6, 2024

Can we switch the order of parameters? So, either having cumulative right after sliding.window?
However, I am not sure whether we have calls to that function that don't explicitly use parameter names and instead rely on the order of parameters... this needs to be checked first...


## 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 reanges

This comment has been minimized.

Copy link
@bockthom

bockthom Sep 6, 2024

reanges ➡️ ranges

if ((offset + 1) <= length(revs)) {
seq2 = revs[ (offset + 1):length(revs) ]
} else {
Expand Down

0 comments on commit 86acadc

Please sign in to comment.