recur_on_position {almanac}R Documentation

Recur on a position within a frequency

Description

recur_on_position() let's you have fine tuned control over which element of the set to select within the base frequency.

Usage

recur_on_position(x, n)

Arguments

x

⁠[rrule]⁠

A recurrence rule.

n

⁠[integer]⁠

The positions to select within an intrafrequency set. Negative numbers select from the end of the set.

Value

An updated rrule.

Examples

library(lubridate, warn.conflicts = FALSE)

start <- "1999-01-01"
end <- "1999-05-01"

# You might want the last day of the month that is either a
# Sunday or a Monday, but you don't want to return both.
# This would return both:
on_last_monday_and_sunday <- monthly() %>%
  recur_on_day_of_week(c("Monday", "Sunday"), nth = -1)

alma_search(start, end, on_last_monday_and_sunday)

# To return just the last one, you would select the last value in
# the set, which is computed on a per month basis
on_very_last_monday_or_sunday <- on_last_monday_and_sunday %>%
  recur_on_position(-1)

alma_search(start, end, on_very_last_monday_or_sunday)

wday(alma_search(start, end, on_very_last_monday_or_sunday), label = TRUE)


[Package almanac version 1.0.0 Index]