Description Usage Arguments Details Examples
sch_adjust()
takes an existing vector of dates and shifts it by applying
an adjustment
whenever a date in x
is also an event defined by
the schedule
.
1 | sch_adjust(x, schedule, adjustment = days(1))
|
x |
A vector of dates. |
schedule |
A schedule or event. |
adjustment |
An adjustment to make whenever a date falls on an event. If this is a lubridate period object, such as If this is a function or formula (i.e., a lambda function), then it
should accept 2 arguments, the dates to adjust and the original |
Internally, a period / integer adjustment
is applied repeatedly until the
next non-event date is found. Be careful! This can result in infinite loops
with improperly defined schedules, which are impossible for us to guard
against for you.
A custom adjustment
function should expect to accept the dates
requiring adjustment, and should completely adjust them to the next
non-event date. It is the responsibility of the adjustment
function to
ensure that the date resulting from the adjustment is not also an
event date.
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 26 27 28 29 30 | library(lubridate, warn.conflicts = FALSE)
# The first of the month is an "event" so we have to adjust
# our current date to avoid that.
sch_adjust("2019-01-01", on_mday(1))
# The adjustment could also be backwards
sch_adjust("2019-01-01", on_mday(1), adjustment = -days(1))
# Period adjustments are applied repeatedly until the next non-event can
# be found. Here, 2019-01-01 is an event, so we move to 2019-01-02, but
# that is an event too, so we move to 2019-01-03.
sch_adjust("2019-01-01", on_mday(1:2))
# ---------------------------------------------------------------------------
# Custom adjustments
# Financial business logic might require special rules, a few of which are
# encoded in the `adj_*()` functions. For example, `adj_modified_following()`
# will use an adjustment of `+days(1)`, unless making that adjustment would
# place you past the last day in the month, in which case an adjustment of
# `-days(1)` is made instead.
sch_adjust("2019-01-31", on_mday(31), adj_modified_following)
# `adj_nearest()` looks to the closest non-event date. Here, the 13th
# is closer than the 18th, so it is chosen as the adjustment date.
sch_adjust("2019-01-15", on_mday(c(14, 15, 16, 17)), adj_nearest)
# When the distance is the same, the following date is chosen
sch_adjust("2019-01-15", on_mday(c(14, 15, 16)), adj_nearest)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.