In a vector of dates, detect the non-business days (holiday or weekend).
Usage
is_holiday(x, holidays)
is_weekend(x, weekend = c("Sat", "Sun"))Arguments
- x
A vector of dates or date-times. If date-times are supplied, the date component will be extracted.
- holidays
A vector of dates that are holidays.
- weekend
A character vector of three-letter abbreviations of weekday names indicating days that should be considered a weekend. Acceptable values are:
"Sun","Mon","Tue","Wed","Thu","Fri","Sat".
Details
Holiday dates can be obtained using get_holidays(), get_province(), or by defining a custom
vector of holidays.
Examples
library(lubridate)
dates <- seq.Date(from = ymd("2025-12-20"), to = ymd("2025-12-31"), by = "1 day")
winter_holidays <- ymd(c("2025-12-25", "2025-12-26"))
rlang::set_names(is_holiday(dates, holidays = winter_holidays), dates)
#> 2025-12-20 2025-12-21 2025-12-22 2025-12-23 2025-12-24 2025-12-25 2025-12-26
#> FALSE FALSE FALSE FALSE FALSE TRUE TRUE
#> 2025-12-27 2025-12-28 2025-12-29 2025-12-30 2025-12-31
#> FALSE FALSE FALSE FALSE FALSE
rlang::set_names(is_weekend(dates), dates)
#> 2025-12-20 2025-12-21 2025-12-22 2025-12-23 2025-12-24 2025-12-25 2025-12-26
#> TRUE TRUE FALSE FALSE FALSE FALSE FALSE
#> 2025-12-27 2025-12-28 2025-12-29 2025-12-30 2025-12-31
#> TRUE TRUE FALSE FALSE FALSE
