add_rholiday: Add an rholiday to an rcalendar

Description Usage Arguments Value Examples

View source: R/rcalendar.R

Description

add_rholiday() adds a new holiday to a calendar. To add a holiday, pass through the corresponding holiday function, without the parenthesis. add_rholiday() will take care of constructing the rholiday object with the correct arguments.

Arguments passed on to the rholiday_fn (such as since and adjust_on) default to the corresponding arguments in the rcalendar, but can be overridden at the rholiday level by supplying them in add_rholiday().

Usage

1
2
3
4
5
6
7
8
9
add_rholiday(
  x,
  rholiday_fn,
  ...,
  since = NULL,
  until = NULL,
  adjust_on = NULL,
  adjustment = NULL
)

Arguments

x

[rcalendar]

An rcalendar.

rholiday_fn

[function]

An rholiday function, such as hldy_christmas. The actual function should be supplied, and add_rholiday() will take care of calling it with the correct arguments.

...

Not used.

since

[NULL / Date(1)]

If NULL, default to the since date of the rcalendar, x.

Otherwise, the lower bound on where to begin looking for the holiday.

until

[NULL / Date(1)]

If NULL, default to the until date of the rcalendar, x.

Otherwise, the upper bound on where to begin looking for the holiday.

adjust_on

[NULL / rschedule]

If NULL, default to the adjust_on of the rcalendar, x.

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

adjustment

[NULL / function]

If NULL, default to the adjustment of the rcalendar, x.

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

Value

x, with a new rholiday.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
library(almanac)

cal <- rcalendar() %>%
  add_rholiday(hldy_christmas) %>%
  add_rholiday(hldy_new_years_day)

cal

alma_in("1999-12-25", cal)


on_weekends <- weekly() %>%
  recur_on_weekends()

# Construct a calendar that rolls weekend Christmas dates to
# the nearest weekday
cal2 <- rcalendar() %>%
  add_rholiday(
    hldy_christmas,
    adjust_on = on_weekends,
    adjustment = adj_nearest
  ) %>%
  add_rholiday(hldy_new_years_day)

alma_search("2004-01-01", "2010-01-01", cal2)

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