From 6305adcee7f18747141994b00bdd94641f95e86f Mon Sep 17 00:00:00 2001 From: Thomas Bock Date: Fri, 12 Apr 2024 17:06:53 +0200 Subject: [PATCH] Check whether custom timestamps are available in `split.data.time.based.by.timestamps` If no custom event timestamps are available in the ProjectData object, an error is thrown in `split.data.time.based.by.timestamps`, to avoid passing `NULL` to the called splitting functions. Signed-off-by: Thomas Bock --- util-split.R | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/util-split.R b/util-split.R index cdbf00bf..a8c26ad9 100644 --- a/util-split.R +++ b/util-split.R @@ -18,7 +18,7 @@ ## Copyright 2020 by Christian Hechtl ## Copyright 2017 by Felix Prasse ## Copyright 2017-2018 by Thomas Bock -## Copyright 2020 by Thomas Bock +## Copyright 2020, 2024 by Thomas Bock ## Copyright 2021 by Niklas Schneider ## Copyright 2021 by Johannes Hostert ## Copyright 2022 by Jonathan Baumann @@ -135,7 +135,7 @@ split.data.by.bins = function(project.data, activity.amount, bins, split.basis = #' and the last range ends with the last timestamp. #' #' If timestamps are not provided, the custom event timestamps in \code{project.data} are -#' used instead. +#' used instead. If no custom event timestamps are available in \code{project.data}, an error is thrown. #' #' @param project.data the *Data object from which the data is retrieved #' @param bins a vector of timestamps [default: NULL] @@ -148,6 +148,12 @@ split.data.time.based.by.timestamps = function(project.data, bins = NULL, projec if (is.null(bins)) { # bins were not provided, use custom timestamps from project bins = unlist(project.data$get.custom.event.timestamps()) + + if (is.null(bins)) { # stop if no custom timestamps are available + logging::logerror("There are no custom timestamps available for splitting (configured file: %s).", + project.data$get.project.conf.entry("custom.event.timestamps.file")) + stop("Stopping due to missing data.") + } } return (split.data.time.based(project.data, bins = bins, project.conf.new));