@@ -59,8 +59,8 @@ calc_arrivals <- function(arrivals, groups = NULL) {
5959 arrivals <- group_by(arrivals , across(all_of(groups )))
6060 }
6161 # Calculate number of arrivals
62- arrivals % > %
63- summarise(arrivals = n_distinct(.data [[" name" ]])) % > %
62+ arrivals | >
63+ summarise(arrivals = n_distinct(.data [[" name" ]])) | >
6464 ungroup()
6565}
6666
@@ -79,11 +79,11 @@ calc_mean_patients_in_service <- function(patient_count, groups = NULL) {
7979 patient_count <- group_by(patient_count , across(all_of(groups )))
8080 }
8181 # Calculate the time-weighted number of patients in the service
82- patient_count % > %
82+ patient_count | >
8383 # Sort by time
84- arrange(.data [[" time" ]]) % > %
84+ arrange(.data [[" time" ]]) | >
8585 # Calculate time between this row and the next
86- mutate(interval_duration = (lead(.data [[" time" ]]) - .data [[" time" ]])) % > %
86+ mutate(interval_duration = (lead(.data [[" time" ]]) - .data [[" time" ]])) | >
8787 # Multiply each patient count by its own unique duration. The total of
8888 # those is then divided by the total duration of all intervals.
8989 # Hence, we are calculated a time-weighted average patient count.
@@ -92,7 +92,7 @@ calc_mean_patients_in_service <- function(patient_count, groups = NULL) {
9292 sum(.data [[" count" ]] * .data [[" interval_duration" ]], na.rm = TRUE ) /
9393 sum(.data [[" interval_duration" ]], na.rm = TRUE )
9494 )
95- ) % > %
95+ ) | >
9696 ungroup()
9797}
9898
@@ -110,14 +110,14 @@ calc_mean_queue <- function(arrivals, groups = NULL) {
110110 group_vars <- c(" resource" , groups )
111111
112112 # Calculate mean queue length for each resource
113- arrivals % > %
114- group_by(across(all_of(group_vars ))) % > %
113+ arrivals | >
114+ group_by(across(all_of(group_vars ))) | >
115115 # Sort by arrival time
116- arrange(.data [[" start_time" ]]) % > %
116+ arrange(.data [[" start_time" ]]) | >
117117 # Calculate time between this row and the next
118118 mutate(
119119 interval_duration = (lead(.data [[" start_time" ]]) - .data [[" start_time" ]])
120- ) % > %
120+ ) | >
121121 # Multiply each queue length by its own unique duration. The total of
122122 # those is then divided by the total duration of all intervals.
123123 # Hence, we are calculated a time-weighted average queue length.
@@ -126,11 +126,11 @@ calc_mean_queue <- function(arrivals, groups = NULL) {
126126 .data [[" interval_duration" ]], na.rm = TRUE ) /
127127 sum(.data [[" interval_duration" ]], na.rm = TRUE )
128128 )
129- ) % > %
129+ ) | >
130130 # Reshape dataframe
131131 pivot_wider(names_from = " resource" ,
132132 values_from = " mean_queue_length" ,
133- names_glue = " mean_queue_length_{resource}" ) % > %
133+ names_glue = " mean_queue_length_{resource}" ) | >
134134 ungroup()
135135}
136136
@@ -156,12 +156,12 @@ calc_mean_wait <- function(arrivals, resources, groups = NULL) {
156156 group_vars <- c(" resource" , groups )
157157
158158 # Calculate mean wait time for each resource
159- complete_arrivals % > %
160- group_by(across(all_of(group_vars ))) % > %
161- summarise(mean_waiting_time = mean(.data [[" wait_time" ]])) % > %
159+ complete_arrivals | >
160+ group_by(across(all_of(group_vars ))) | >
161+ summarise(mean_waiting_time = mean(.data [[" wait_time" ]])) | >
162162 pivot_wider(names_from = " resource" ,
163163 values_from = " mean_waiting_time" ,
164- names_glue = " mean_waiting_time_{resource}" ) % > %
164+ names_glue = " mean_waiting_time_{resource}" ) | >
165165 ungroup()
166166 } else {
167167 # But if no patients are seen, create same tibble with values set to NA
@@ -195,12 +195,12 @@ calc_mean_serve_length <- function(arrivals, resources, groups = NULL) {
195195 group_vars <- c(" resource" , groups )
196196
197197 # Calculate mean serve time for each resource
198- complete_arrivals % > %
199- group_by(across(all_of(group_vars ))) % > %
200- summarise(mean_serve_time = mean(.data [[" serve_length" ]])) % > %
198+ complete_arrivals | >
199+ group_by(across(all_of(group_vars ))) | >
200+ summarise(mean_serve_time = mean(.data [[" serve_length" ]])) | >
201201 pivot_wider(names_from = " resource" ,
202202 values_from = " mean_serve_time" ,
203- names_glue = " mean_serve_time_{resource}" ) % > %
203+ names_glue = " mean_serve_time_{resource}" ) | >
204204 ungroup()
205205 } else {
206206 # But if no patients are seen, create same tibble with values set to NA
@@ -239,8 +239,8 @@ calc_utilisation <- function(resources, groups = NULL, summarise = TRUE) {
239239 group_vars <- c(" resource" , groups )
240240
241241 # Calculate utilisation
242- util_df <- resources % > %
243- group_by(across(all_of(group_vars ))) % > %
242+ util_df <- resources | >
243+ group_by(across(all_of(group_vars ))) | >
244244 mutate(
245245 # Time between this row and the next
246246 interval_duration = lead(.data [[" time" ]]) - .data [[" time" ]],
@@ -256,18 +256,18 @@ calc_utilisation <- function(resources, groups = NULL, summarise = TRUE) {
256256
257257 # If summarise = TRUE, find total utilisation
258258 if (summarise ) {
259- util_df % > %
259+ util_df | >
260260 summarise(
261261 # Multiply each utilisation by its own unique duration. The total of
262262 # those is then divided by the total duration of all intervals.
263263 # Hence, we are calculated a time-weighted average utilisation.
264264 utilisation = (sum(.data [[" utilisation" ]] *
265265 .data [[" interval_duration" ]], na.rm = TRUE ) /
266266 sum(.data [[" interval_duration" ]], na.rm = TRUE ))
267- ) % > %
267+ ) | >
268268 pivot_wider(names_from = " resource" ,
269269 values_from = " utilisation" ,
270- names_glue = " utilisation_{resource}" ) % > %
270+ names_glue = " utilisation_{resource}" ) | >
271271 ungroup()
272272 } else {
273273 # If summarise = FALSE, just return the util_df with no further processing
@@ -288,12 +288,12 @@ calc_unseen_n <- function(arrivals, groups = NULL) {
288288 # Create list of grouping variables (always "resource", but can add others)
289289 group_vars <- c(" resource" , groups )
290290 # Calculate number of patients waiting
291- arrivals % > %
292- group_by(across(all_of(group_vars ))) % > %
293- summarise(value = sum(! is.na(.data [[" wait_time_unseen" ]]))) % > %
291+ arrivals | >
292+ group_by(across(all_of(group_vars ))) | >
293+ summarise(value = sum(! is.na(.data [[" wait_time_unseen" ]]))) | >
294294 pivot_wider(names_from = " resource" ,
295295 values_from = " value" ,
296- names_glue = " count_unseen_{resource}" ) % > %
296+ names_glue = " count_unseen_{resource}" ) | >
297297 ungroup()
298298}
299299
@@ -311,11 +311,11 @@ calc_unseen_mean <- function(arrivals, groups = NULL) {
311311 # Create list of grouping variables (always "resource", but can add others)
312312 group_vars <- c(" resource" , groups )
313313 # Calculate wait time of unseen patients
314- arrivals % > %
315- group_by(across(all_of(group_vars ))) % > %
316- summarise(value = mean(.data [[" wait_time_unseen" ]], na.rm = TRUE )) % > %
314+ arrivals | >
315+ group_by(across(all_of(group_vars ))) | >
316+ summarise(value = mean(.data [[" wait_time_unseen" ]], na.rm = TRUE )) | >
317317 pivot_wider(names_from = " resource" ,
318318 values_from = " value" ,
319- names_glue = " mean_waiting_time_unseen_{resource}" ) % > %
319+ names_glue = " mean_waiting_time_unseen_{resource}" ) | >
320320 ungroup()
321321}
0 commit comments