How to execute taskscheduler_create() on multiple days on a monthly basis?

252 Views Asked by At

I have a query and I want to execute it on the two first days of the month and this happens every month. I used the following code but I received an error:

taskscheduler_create(taskname = "test", rscript = "C:/Users/Public/TaskScheduler/test.R",  schedule = "MONTHLY", startdate = format(as.Date("2021-02-16"), "%m/%d/%Y"), starttime = "15:22", days =c(1:2))

This is the error:

[1] "ERROR: Invalid value for /D option."     "Type \"SCHTASKS /CREATE /?\" for usage."

attr(,"status") [1] 16389

I am also aware of task_scheduler addon but I prefer writing a code for it.

1

There are 1 best solutions below

0
On

i'm not sure if there is anything actually/directly in the formula, but you can use a loop:

map(1:10, function(n) {
  
  taskscheduler_create(taskname = paste("task_name", str_pad(n, 2 , side = "left", pad = "0"), sep = "-"),
                       rscript = "C:/file_path/file_name.R", 
                       schedule = "MONTHLY", starttime = "12:30", days = n,
                       startdate = format(Sys.Date(), "%m/%d/%Y"))
  
} )