Package 'dialga'

Title: Build and Interpret Cron Strings with R
Description: Provide R integer vectors as inputs and get a standard cron string in return. You can also supply a cron string and get an English interpretation in return.
Authors: Matt Dray [aut, cre]
Maintainer: Matt Dray <[email protected]>
License: MIT + file LICENSE
Version: 0.1.1
Built: 2024-10-15 04:45:18 UTC
Source: https://github.com/matt-dray/dialga

Help Index


Internal R Expression to Cron String Procedure

Description

Convert time-period arguments of r2cron from R expressions to the most appropriate cron expression format and paste them together.

Usage

.as_cron(x, p)

Arguments

x

The user's input for a time period argument in the r2cron function

p

Valid cron time periods used in the r2cron function.

Value

A character string.


Internal Stopifnot Procedure

Description

Check that inputs to each time-period argument of r2cron are valid.

Usage

.stop(x, p = c("minutes", "hours", "days_month", "months", "days_week"))

Arguments

x

The user's input for a time period argument in the r2cron function

p

Valid cron time periods used in the r2cron function.

Value

Error if it fails.


Convert a Vector to a Sentence

Description

Paste elements of a vector into sentence form, so that items are separated by commas and the last is separated with the word 'and'. Used for output in cron2eng.

Usage

.vec2eng(x)

Arguments

x

A vector.

Value

A character string.


Generate English Interpretation of Valid Cron Strings

Description

Demystify the meaning of a valid cron string by converting it to an equivalent sentence in English. Can take the output from r2cron for example. (Under development.)

Usage

cron2eng(cron = "* * * * *")

Arguments

cron

Character. A valid cron expression, i.e. a string with five time period 'slots' (minutes, hours, days of the month, months, days of the week), separated by spaces. See details for more information.

Details

The cron string slots and their valid ranges are:

  • Slot 1: minutes past the hour, integers 0 to 59 inclusive.

  • Slot 2: hours on a 24-hour clock, integers 0 to 23 inclusive.

  • Slot 3: day number of the month, integers 1 to 31 inclusive.

  • Slot 4: month number, integers 1 to 12 inclusive.

  • Slot 5: day of the week, integers 0 to 6 inclusive (where Sunday is the first day of the week).

In addition, the following input formats are acceptable to all the time slots:

  • a single integer value, like 1

  • consecutive-integer vectors, like 1:3

  • nonconsecutive, irregularly-spaced integer vectors, like c(2, 3, 5)

  • regularly-spaced integer sequences with specified start and end values, like seq(3, 59, 15) (useful for specifying sequences within the full time period,'every 15 minutes of the hour starting from minute 3', like in this example)

Value

Result printed to console. An English sentence interpretation of the cron string that was the input.

Examples

## Not run: 
cron2eng("1,2,5 2-3 * 1/3 5")
## End(Not run)

Build Cron Strings from R Expressions

Description

Provide an R expression to each of the arguments, which are different time periods (minutes, hours, days of the month, months, days of the week), and receive an equivalent cron-expression string in return. See 'arguments' for valid value ranges and 'details' for valid input formats.

Usage

r2cron(
  minutes = 0L:59L,
  hours = 0L:23L,
  days_month = 1L:31L,
  months = 1L:12L,
  days_week = 1L:7L,
  clip = FALSE
)

Arguments

minutes

Minutes past the hour, integers 0 to 59 inclusive.

hours

Hours on a 24-hour clock, integers 0 to 23 inclusive.

days_month

Day number of the month, integers 1 to 31 inclusive.

months

Month number, integers 1 to 12 inclusive.

days_week

Day of the week, integers 1 to 7 inclusive (where Sunday is the first day of the week).

clip

Logical. Copy output to clipboard? Windows, macOS and X11 only. Requires installation of the clipr package.

Details

The time-period arguments default to every unit within that time period, like 'every minute, of every hour, of every day of the month, etc'. The following input formats are acceptable inputs to all the time period arguments:

  • a single integer value, like 1

  • consecutive-integer vectors, like 1:3

  • nonconsecutive, irregularly-spaced integer vectors, like c(2, 3, 5)

  • regularly-spaced integer sequences with specified start and end values, like seq(3, 59, 15) (useful for specifying sequences within the full time period,'every 15 minutes of the hour starting from minute 3', like in this example)

Value

A character string (copied to the clipboard at the user's discretion).

Examples

## Not run: 
r2cron(
  minutes = seq(0, 59, 20),
  hours = 15:17,  # 24-hr clock
  days_month = 1,
  months = c(4, 10, 11),
  days_week = c(1, 7),  # Sunday is '1'
  clip = FALSE
)
## End(Not run)