diff --git a/R/add_case.R b/R/add_case.R index e5336f9..07642a6 100644 --- a/R/add_case.R +++ b/R/add_case.R @@ -5,13 +5,13 @@ add_case <- function(data, cutoff = 20) { # TODO: What is the best choice for the cutoff here? - data$timediff <- as.numeric(diff(c(data$date.start, utils::tail(data$date.start, 1)))) - data$timeindex <- ifelse(data$timediff <= cutoff, 0, 1) - case_change <- diff(c(0, c(which(data$timeindex == 1), nrow(data)))) - data$case <- rep(seq_along(case_change), case_change) + data$timediff <- -c(utils::head(data$date.stop, nrow(data) - 1) - data$date.start[-1], 0) + data$timeindex <- ifelse(data$timediff <= cutoff, 0, 1) + case_change <- diff(c(0, c(which(data$timeindex == 1), nrow(data)))) + data$case <- rep(seq_along(case_change), case_change) - data$timediff <- NULL - data$timeindex <- NULL + data$timediff <- NULL + data$timeindex <- NULL data } diff --git a/R/create_eventlogs.R b/R/create_eventlogs.R index 80f3d5c..170a2c5 100644 --- a/R/create_eventlogs.R +++ b/R/create_eventlogs.R @@ -14,12 +14,13 @@ #' @param glossar Logical indicating if glossar folder is present and if it #' should be taken into account when preprocessing raw log files. Default #' is FALSE. +#' @param save Temporary argument to save intermediate data frames for debugging. #' @return Data frame. #' @export #' @examples #' # tbd create_eventlogs <- function(data, xmlpath = NULL, case_cutoff = 20, - rm_nochange_moves = TRUE, glossar = FALSE) { + rm_nochange_moves = TRUE, glossar = FALSE, save = FALSE) { if (!lubridate::is.POSIXt(data$date)){ cat("########## Converting variable `date` to POSIXct ##########", "\n") @@ -128,6 +129,8 @@ create_eventlogs <- function(data, xmlpath = NULL, case_cutoff = 20, dat7$glossar <- NULL } + if (save) save(dat, dat1, dat2, dat3, dat4, dat5, dat6, dat7, file = "../data/tmp_intermediate-df.RData") + dat7 } diff --git a/man/create_eventlogs.Rd b/man/create_eventlogs.Rd index aa8de43..c775370 100644 --- a/man/create_eventlogs.Rd +++ b/man/create_eventlogs.Rd @@ -9,7 +9,8 @@ create_eventlogs( xmlpath = NULL, case_cutoff = 20, rm_nochange_moves = TRUE, - glossar = FALSE + glossar = FALSE, + save = FALSE ) } \arguments{ @@ -28,6 +29,8 @@ removed. Default is TRUE.} \item{glossar}{Logical indicating if glossar folder is present and if it should be taken into account when preprocessing raw log files. Default is FALSE.} + +\item{save}{Temporary argument to save intermediate data frames for debugging.} } \value{ Data frame.