on_nth: Schedule the nth events of a period

View source: R/nth.R

on_nthR Documentation

Schedule the nth events of a period

Description

Given a schedule of events, create a new schedule of only the nth occurrences within a given period.

Usage

on_nth(n, x, within_given)

on_first(x, within_given)

on_second(x, within_given)

on_third(x, within_given)

on_fourth(x, within_given)

on_last(x, within_given)

Arguments

n

A single integer specifying which event to select. A negative integer will select the nth last event (i.e. -1L will select the last event of the period, -2L will return the second last etc).

x

A schedule from which to select events.

within_given

A period from within which to select events. Can be either:

  • A string shortcut for a period type: either "day", "week", "month", "quarter" or "year". Or,

  • A date accessor function. Eg. lubridate::month().

Details

Convenience functions are provided for the first, second, third, fourth and last events of a given period.

All functions accept arbitrarily complex schedules. For example, if you wanted a schedule of events occurring on the 12th either Tuesday or Thursday of the quarter you would use: on_nth(12, on_wday("Tue", "Thu"), within_given = "quarter").

Value

A schedule object.

Examples

tuesday <- on_wday("Tue")

second_tuesday_month <- on_second(tuesday, within_given = "month")
schedule_days(second_tuesday_month, during = 2000)

last_tuesday_year <- on_last(tuesday, within_given = "year")
schedule_days(last_tuesday_year, during = 2000)

tenth_tuesday_quarter <- on_nth(10, tuesday, within_given = "quarter")
schedule_days(tenth_tuesday_quarter, during = 2000)

tues_or_thurs <- on_wday("Tue", "Thu")

tenth_tues_or_thurs_quarter <- on_nth(10, tues_or_thurs, within_given = "quarter")
schedule_days(tenth_tues_or_thurs_quarter, during = 2000)


jameslairdsmith/scheduler documentation built on July 27, 2023, 6:06 p.m.