new_rholiday: Create a new holiday

Description Usage Arguments Value Examples

View source: R/rholiday.R

Description

new_rholiday() constructs a new rholiday object. An rholiday is an rschedule that can be used with any almanac function, like almanac::alma_events(). rholidays can also be added to rcalendars through add_rholiday().

Usage

1
2
3
4
5
6
7
8
new_rholiday(
  name,
  since,
  until,
  generator,
  adjust_on = NULL,
  adjustment = NULL
)

Arguments

name

[character(1)]

A required name for the holiday.

since

[Date(1)]

The lower bound on where to begin looking for the holiday.

until

[Date(1)]

The upper bound on where to end looking for the holiday.

generator

[function]

A function that generates an rschedule for the holiday. The function takes two arguments, since and until, which should be passed to the created rschedule.

adjust_on

[NULL / rschedule]

If NULL, no adjustment is made.

Otherwise, an rschedule that defines when an adjustment should be made. For example, set to an rschedule for "on weekends", and supply an adjustment of adj_nearest() to roll holidays that fall on a weekend to the nearest weekday.

adjustment

[NULL / function]

If NULL, no adjustment is made to the holiday.

Otherwise, an adjustment function to apply to problematic dates. Typically one of the pre-existing adjustment functions, like almanac::adj_nearest().

Value

A rholiday.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
library(almanac)

thanksgiving_generator <- function(since, until) {
  yearly(since = since, until = until) %>%
    recur_on_ymonth("November") %>%
    recur_on_wday("Thursday", nth = 4)
}

thanksgiving <- new_rholiday(
  name = "thanksgiving",
  since = "1950-01-01",
  until = "1980-01-01",
  generator = thanksgiving_generator
)

thanksgiving

alma_events(thanksgiving)

DavisVaughan/vacation documentation built on May 2, 2020, 11:07 a.m.