R/dog_aabningstid.R

Defines functions dog_aabningstid

Documented in dog_aabningstid

#' Aabningstid
#'
#' Keep only observations that are in the openings hours. Requires that the columns created by date_column.
#'
#' The date_columns function has to be run before we can use this function.
#'
#' @param df A data frame that has these components from a timestamp: date, weekday, and hour_min.
#' @param x A vector containing closed days.
#'
#' @return A subset of the rows. weekday = 7 is saturday and weekday = 1 is sunday.
#' @export
#' @examples
#' dog_date_columns(tibble::tibble(time = paste(Sys.time())), time) %>%
#'  dog_aabningstid()
dog_aabningstid <- function(df, x = NULL){
  suppressWarnings(
    df %>%
    dplyr::filter(!.data$date %in% x) %>%
    dplyr::filter(!.data$weekday %in% c(7, 1)) %>%
    dplyr::filter((dplyr::between(.data$hour_min, as.numeric(hms::as.hms("08:00:00")), as.numeric(hms::as.hms("14:59:59")))
            & .data$weekday %in% c(2:5))  |
             (.data$weekday %in% c(6)
              & dplyr::between(.data$hour_min, as.numeric(hms::as.hms("08:00:00")), as.numeric(hms::as.hms("14:30:00")))  )           )
)
}
davidbaniadam/rispacs documentation built on Nov. 4, 2019, 9:43 a.m.