customscheduleR provides greater flexibility to customize run dates when using cronR or taskscheduleR through the customize_schedule()
wrapper function. While standard job scheduling packages allow for running on specific days of the week or days of the month, further specifications are not as feasible to create. The customscheduleR package allows:
-
Running jobs on specific dates only
-
Skipping runs on specific dates (such as holidays) and providing the option to run the next day
-
Running jobs biweekly
-
Running jobs on specific days of the month and providing the option to select the first out of the specific days, accounting for the option to not run on weekends or holidays
-
Running jobs on the last day of the month accounting for the option to not run on weekends or holidays
-
Getting a data frame of dates in the year the script will run.
The current version requires separate installation of cronR or taskscheduleR and a daily job at the desired time and daily frequency (minute, hourly or daily). The customscheduleR package then provides the option defining criteria for the specific days in the current year the script should/should not run. The start date refreshes to January 1st at the beginning of every year.
You can install the development version of customscheduleR from GitHub with:
# install.packages("devtools")
devtools::install_github("samiaab1990/customscheduleR")
Note: This version of customschedule R requires separate installation of cronR and taskscheduleR and a job already added for the specific task which customscheduleR will be used for.
The customize_schedule()
function should be placed after library(customscheduleR)
is called and before the rest of the script that should run on the specific day.
library(customscheduleR)
# At the beginning of the desired script
customize_schedule(
# A specific start date if desired in YYYY-mm-dd format. If none is specified, default to January 1st of the year
start_date = "2022-01-01",
# Allows filtering specific date(s) the script should run in YYYY-mm-dd format
specific dates = c("2022-02-01", "2022-02-02"),
# Allows specifying specific days of the week the script should run
days_of_week = c("Monday","Tuesday"),
# Runs every other week if true
biweekly = TRUE,
# Skips Saturday and Sunday if TRUE. A simplified argument alternative to specifying Monday-Friday in days_of_week
skip_weekends = TRUE,
# Allows the option to skip specific dates (ie: holiday dates)
dates_to_skip = "2022-07-04",
# If date or date vector is provided in dates_to_skip, asks if the script should be run the next day. Note this accounts for if options are set to run on specific days of the week or skip weekdays.
run_next_day = TRUE,
# Integer between 1-31 specifying the day or days of month the script should run
days_of_month= c(1:7),
# If days are provided in days_of_month, selects the first (minimum day) out of the days_of_month
select_min = TRUE,
# Selects the last day of the month accounting for other criteria (weekends, holidays, specific days of week, etc.)
select_last = TRUE,
# Returns a data frame with specific run dates for the year
get_dataset = TRUE
)
If the current system date is within the date parameters defined in custom_schedule()
, the job will run and print a successful run in the log file. If the current system date is not within the date parameters defined in custom_schedule()
, the function returns an error and halts the rest of the script.