How to schedule taskscheduleR once a month at the start of every month?

1.8k Views Asked by At

Looking to run R script once a month at the first of every month.I've figured out how to run it via task scheduler with the taskscheduleR library. Here is the current cadence I have set on it:

taskscheduler_create(taskname = "Rebate Automation2", rscript = myscript, 
                     schedule = "MONTHLY", starttime = "12:30")

I am unsure how to set it for the first of every month.

2

There are 2 best solutions below

0
On BEST ANSWER

From the package documentation:

days     character string with days on which to run the script if schedule is
’WEEKLY’or ’MONTHLY’. Possible values are * (all days). For weekly: ’MON’,
’TUE’,’WED’, ’THU’, ’FRI’, ’SAT’, ’SUN’ or a vector of these in your locale. 
For monthly: 1:31 or a vector of these.

Therefore taskscheduler_create(taskname = "Rebate Automation2", rscript = myscript, schedule = "MONTHLY", days=1, starttime = "12:30")

Should do the job.

0
On

The documentation for taskscheduleR::taskscheduler_create can be found (1) by pressing F1 and clicking on the function call taskscheduler_create; or (2) on pages 3 and 4 of the manual. Per this documentation, the days parameter

taskscheduler_create(
  ...
  days = c("*", "MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN", 1:31),
  ...
)

can be set to days = 1 for schedule = "MONTHLY", to trigger on the first day of every month:

character string with days on which to run the script if schedule is ’WEEKLY’ or ’MONTHLY’. Possible values are * (all days). For weekly: ’MON’, ’TUE’, ’WED’, ’THU’, ’FRI’, ’SAT’, ’SUN’ or a vector of these in your locale. For monthly: 1:31 or a vector of these.

So you'd want to use

taskscheduler_create(taskname = "Rebate Automation2", rscript = myscript, 
                     schedule = "MONTHLY", days = 1, starttime = "12:30")
#                                          ^^^^^^^^