adjustments {almanac}R Documentation

Date adjustments


This family of ⁠adj_*()⁠ functions encode business logic for common date adjustments. If x falls on an event date, it is adjusted according to the function's adjustment rule. Otherwise it is left untouched.


adj_following(x, rschedule)

adj_preceding(x, rschedule)

adj_modified_following(x, rschedule)

adj_modified_preceding(x, rschedule)

adj_nearest(x, rschedule)

adj_none(x, rschedule)




A vector of dates.



An rschedule, such as an rrule, runion, rintersect, or rsetdiff.


An adjusted vector of Dates.


# A Saturday
x <- as.Date("1970-01-03")

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

# Adjust forward to Monday
adj_following(x, on_weekends)

# Adjust backwards to Friday
adj_preceding(x, on_weekends)

# Adjust to nearest non-event date
adj_nearest(x, on_weekends)
adj_nearest(x + 1, on_weekends)

# Sundays, one of which is at the end of the month
sundays <- as.Date(c("2020-05-24", "2020-05-31"))

# Adjust forward, unless that takes us into a new month, in which case we
# adjust backwards.
adj_modified_following(sundays, on_weekends)

# Saturdays, one of which is at the beginning of the month
saturdays <- as.Date(c("2020-08-01", "2020-08-08"))

# Adjust backwards, unless that takes us into a new month, in which
# case we adjust forwards
adj_modified_preceding(saturdays, on_weekends)

[Package almanac version 1.0.0 Index]