R/merge_schedule_files.R

Defines functions merge_schedule_files

Documented in merge_schedule_files

#' Merge Schedule Files
#'
#' Takes a list of paths to HTML files downloaded from Medinet, imports them
#' using `load_tidy_schedule()` and merges them for analysis, removing duplicate
#' entries.
#'
#' @param list_of_file_paths A list of paths to HTML files downloaded from
#'   Medinet.
#'
#' @return A tibble like that returned by `load_tidy_schedule()`.
#' @export
#' @seealso [medinetparser::load_tidy_schedule()]
#' @md
#'
#' @examples
#' \dontrun{
#' c('path/to/first/file.html', 'path/to/second/file.html') |>
#'   merge_schedule_files()}
merge_schedule_files <- function(list_of_file_paths) {
  return_tibble <-
    list_of_file_paths[1] |>
    load_tidy_schedule()

  if (length(list_of_file_paths) > 1) {
    for (schedule_file in list_of_file_paths[2:length(list_of_file_paths)]) {
      return_tibble <-
        return_tibble |>
        dplyr::bind_rows(
          schedule_file |>
            load_tidy_schedule() |>
            dplyr::filter(!(date %in% dplyr::pull(return_tibble, date)))
        )
    }
  }

  return(return_tibble)
}
JonasEngstrom/medinetparser documentation built on April 20, 2024, 12:41 a.m.