R/n_traces.R

Defines functions n_traces.grouped_log n_traces.log n_traces

Documented in n_traces n_traces.grouped_log n_traces.log

#' @title n_traces
#' @description Returns the number of traces in an event log
#' @inheritParams act_collapse
#' @family Counters
#' @export n_traces

n_traces <- function(log, eventlog = deprecated()) {
	UseMethod("n_traces")
}

#' @describeIn n_traces Count number of traces for eventlog
#' @export

n_traces.log <- function(log, eventlog = deprecated()) {
	eventlog <- lifecycle_warning_eventlog(log, eventlog)

	nrow(trace_list(eventlog))
}

#' @describeIn n_traces Count number of traces for grouped eventlog
#' @export
n_traces.grouped_log <- function(log, eventlog = deprecated()) {
	eventlog <- lifecycle_warning_eventlog(log, eventlog)

	mapping <- mapping(eventlog)

	log %>%
		# remove grouping
		ungroup() %>%
		# group_by + nest (has option to keep group-vars in nested data)
		nest_by(across(mapping$groups), .keep = TRUE) %>%
		# nest_by returns rowwise data.frame, which we don't need
		ungroup() %>%
		# make sure data is event log
		mutate(data = map(data, re_map, mapping)) %>%
		# compute output of function, taking over any arguments
		mutate(n_traces = map_dbl(data, n_traces)) %>%
		select(-data)
}

Try the bupaR package in your browser

Any scripts or data that you put into this service are public.

bupaR documentation built on May 29, 2024, 7:46 a.m.