on_every_nth: Make incremental events

View source: R/every.R

on_every_nthR Documentation

Make incremental events

Description

Create a schedule of events occuring in increments from a fixed date.

Usage

on_every_nth(n, unit, starting, inclusive = TRUE, backdated = FALSE)

on_every(unit, starting, inclusive = TRUE, backdated = FALSE)

on_every_second(unit, starting, inclusive = TRUE, backdated = FALSE)

in_every_nth(n, unit, starting, inclusive = TRUE, backdated = FALSE)

in_every(unit, starting, inclusive = TRUE, backdated = FALSE)

in_every_second(unit, starting, inclusive = TRUE, backdated = FALSE)

Arguments

n

A single integer specifying the increment of the events to create. Eg. 2L for every second event.

unit

The type of period to increment. Can be either:

  • A character shortcut for a period object. Eg. "year", "years", "month", "months", "week", "weeks" etc. Can be any value accepted by lubridate::period().

  • A schedule object. Eg. on_weekday() for events occuring every n weekdays.

starting

The first event of the series. Can be a date or datetime.

inclusive

Logical indicating whether the starting date should be included in the resulting schedule.

backdated

Logical indicating whether dates prior the starting date should be included in the resulting schedule.

Details

on_every() and on_every_second() are convenience functions for on_every_nth() where the n argument is pre-filled with 1L and 2L respectively.

Value

A schedule object.

Examples

monthly_from_millenium_start <- on_every("month", as.Date("2000-01-01"))
schedule_days(monthly_from_millenium_start, during = 2000)

fortnightly_from_millenium_start <- on_every_second("week", as.Date("2000-01-01"))
schedule_days(fortnightly_from_millenium_start, during = 2000)

tenth_weekend_day_from_millenium_start <- on_every_nth(10, on_weekend(), as.Date("2000-01-01"))
schedule_days(tenth_weekend_day_from_millenium_start, during = 2000)

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