on_event: Events related to other events

Description Usage Arguments Examples

View source: R/on-event.R

Description

on_event() defines an alternative date to use as an event if event occurs. It is usually useful as a way to deviate from a normal schedule in the case of an unusual circumstance.

Usage

1
on_event(x, event, jump)

Arguments

x

[event]

An event defining normal behavior.

event

[event]

An event defining when a jump should occur.

jump

[Period(1) / integer(1)]

A jump defining the deviation from normal behavior.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
# Imagine the garbage truck normally comes every Monday, but if
# Monday is a state holiday, then it comes on Tuesday instead. In this case
# we can use `event = on_state_holiday` as a trigger to define an alternative
# event rule.

on_normal_trash_day <- on_wday("Monday")
on_state_holiday <- on_month("Sep") & on_mweek(1) & on_wday("Monday")

on_trash_day <- on_event(on_normal_trash_day, on_state_holiday, days(1))

# A Monday in September
event_in("2019-09-09", on_normal_trash_day)
event_in("2019-09-09", on_trash_day)

# Labor Day Monday should not be trash day
event_in("2019-09-02", on_normal_trash_day)
event_in("2019-09-02", on_trash_day)

# The day after Labor Day Monday is trash day
event_in("2019-09-03", on_normal_trash_day)
event_in("2019-09-03", on_trash_day)

DavisVaughan/almanac3 documentation built on Oct. 30, 2019, 5:59 a.m.