sch_jump()
shifts a sequence of dates by "jumping" from x
to
x + jump
. After the jump, sch_adjust()
is called with the adjustment
to ensure that if the new dates are events, they are adjusted to the next
available non-event date.
sch_step()
steps over a sequence of dates 1 day at a time, for n
days.
After each step, sch_adjust()
is called with an adjustment of days(1)
.
This has different results from sch_jump()
with a jump of days(n)
, and
is more appropriate for shifting by "n business days".
sch_jump(x, jump, schedule, adjustment = days(1)) sch_step(x, n, schedule)
x |
A vector of dates. |
---|---|
jump |
A lubridate period object, such as |
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 |
n |
The number of days to step. Can be negative to step backwards. |
For shifting by "n business days", sch_step()
is often more appropriate.
Imagine you are on a Friday and want to shift forward 2 days using a
schedule that marks weekends as events. There are two options:
sch_jump()
- Jump forward 2 days to Sunday, and apply the adjustment
.
Assuming adjustment = days(1)
was used, that means the result is Monday.
sch_step()
- Step forward 1 day to Saturday, apply an adjustment of
days(1)
, which rolls forward to Monday. Step forward 1 day to Tuesday,
and no further adjustment is required.
The second option more naturally lends itself to business logic. Two business days from Friday is Tuesday.
# 2019-09-13 is a Friday # Note that here we "jump" to Sunday, then adjust, leaving us on Monday sch_jump("2019-09-13", days(2), on_weekends())#> [1] "2019-09-16"# Here we step 1 day to Saturday, adjust to Monday, # then step 1 day to Tuesday sch_step("2019-09-13", 2, on_weekends())#> [1] "2019-09-17"