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

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.

Value

A schedule object.

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.

Examples

monthly_from_millenium_start <- on_every("month", as.Date("2000-01-01")) schedule_days(monthly_from_millenium_start, during = 2000)
#> [1] "2000-01-01" "2000-02-01" "2000-03-01" "2000-04-01" "2000-05-01" #> [6] "2000-06-01" "2000-07-01" "2000-08-01" "2000-09-01" "2000-10-01" #> [11] "2000-11-01" "2000-12-01"
fortnightly_from_millenium_start <- on_every_second("week", as.Date("2000-01-01")) schedule_days(fortnightly_from_millenium_start, during = 2000)
#> [1] "2000-01-01" "2000-01-15" "2000-01-29" "2000-02-12" "2000-02-26" #> [6] "2000-03-11" "2000-03-25" "2000-04-08" "2000-04-22" "2000-05-06" #> [11] "2000-05-20" "2000-06-03" "2000-06-17" "2000-07-01" "2000-07-15" #> [16] "2000-07-29" "2000-08-12" "2000-08-26" "2000-09-09" "2000-09-23" #> [21] "2000-10-07" "2000-10-21" "2000-11-04" "2000-11-18" "2000-12-02" #> [26] "2000-12-16" "2000-12-30"
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)
#> [1] "2000-01-01" "2000-02-05" "2000-03-11" "2000-04-15" "2000-05-20" #> [6] "2000-06-24" "2000-07-29" "2000-09-02" "2000-10-07" "2000-11-11" #> [11] "2000-12-16"