R/tally_shifts.R

Defines functions tally_shifts

Documented in tally_shifts

#' Tally Shifts
#'
#' Takes a tidy schedule generated by `load_tidy_schedule()` and generates a
#' table of shift tallies per doctor.
#'
#' @param tidy_schedule A tibble generated by `load_tidy_schedule()`.
#'
#' @return A tibble with tallies of shift types per doctor.
#' @export
#' @seealso [medinetparser::load_tidy_schedule()]
#' @md
#'
#' @examples
#' tally_table <- tally_shifts(example_schedule)
tally_shifts <- function(tidy_schedule) {
  NULL ->
    doctor_name ->
    shift_type ->
    n

  tidy_schedule |>
    dplyr::group_by(doctor_name, shift_type) |>
    dplyr::tally() |>
    tidyr::pivot_wider(names_from = shift_type, values_from = n) |>
    dplyr::mutate(dplyr::across(dplyr::everything(), ~ tidyr::replace_na(.x, 0))) |>
    (\(x) return(x))()
}
JonasEngstrom/medinetparser documentation built on April 20, 2024, 12:41 a.m.