sch_jump: Shift dates relative to a schedule

Description Usage Arguments Details Examples

View source: R/sch-shift.R

Description

Usage

1
2
3
sch_jump(x, jump, schedule, adjustment = days(1))

sch_step(x, n, schedule)

Arguments

x

[Date]

A vector of dates.

jump

[Period(1) / character(1)]

A lubridate period object, such as lubridate::days() or lubridate::years(). This can also be a character string parsable by lubridate::period(). Sub-daily periods are not allowed.

schedule

[schedule / event]

A schedule or event.

adjustment

[Period(1) / integer(1) / function / formula]

An adjustment to make whenever a date falls on an event.

If this is a lubridate period object, such as lubridate::days(), or an integer, then the adjustment is repeatedly applied as x + adjustment until the next non-event date is found.

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 schedule, and should return a Date vector of the same size as the original input containing the adjusted dates. See the functions on the help page for adj_following() for some examples.

n

[integer(1)]

The number of days to step. Can be negative to step backwards.

Details

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:

The second option more naturally lends itself to business logic. Two business days from Friday is Tuesday.

Examples

1
2
3
4
5
6
7
8
# 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())

# Here we step 1 day to Saturday, adjust to Monday,
# then step 1 day to Tuesday
sch_step("2019-09-13", 2, on_weekends())

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