bnosac / taskscheduleR

Schedule R scripts/processes with the Windows task scheduler.
331 stars 72 forks source link

How to specify more than one weekday? #43

Closed rluech closed 6 years ago

rluech commented 6 years ago

Very handy package, thanks! How can I specify the script to run from Monday to Friday but not on Weekends? According to the error message days = only takes a length one character vector:

taskscheduler_create(...,
  schedule  = 'WEEKLY',
  days      = list(c('MON','TUE','WED','THU','FRI')),
)

Error in match.arg(days) : 'arg' must be NULL or a character vector

taskscheduler_create(...,
  schedule  = 'WEEKLY',
  days      = c('MON','TUE','WED','THU','FRI'),
)

Error in match.arg(days) : 'arg' must be of length 1

By the way, does the language of the locale matter as we specify english lables

jwijffels commented 6 years ago

Interesting question, I normally don't use these schedules, but I've changed the package so that this is now possible. The following below schedules on sunday and saturday e.g. I have the impression that you need locale specific days of week. Can't check that as I've set my windows machine on a english locale. If you have another language, you probably need to change the days to your locale.

Please test using the current version of the package on github and let me know if it worked.

taskscheduler_create(taskname = "myfancyscript_sunsat", rscript = myscript, 
                     schedule = "WEEKLY", starttime = "09:10", days = c('SUN', 'SAT'))
rluech commented 6 years ago

Cool, it seems to work. Thanks devtool::install_github("bnosac/taskscheduleR") (after initial errors / conflict with data.table) taskscheduler_create(..., days = c("MON",TUE", ...)) now accepts a Character vector length > 1 cmd taskschd.msc on German Windows 10 displays a propper task as intended, so english input seem correctly interpreted. Will see definately the after weekend.

jwijffels commented 6 years ago

Great. Let me know if it worked for your setting next week. The same logic was implemented if you want to schedule only certain months in the monthly setting.

jwijffels commented 6 years ago

If this worked, can you close the issue?

rluech commented 6 years ago

I didn't forget to give feedback. But, unfortunately I have to tell the Windows taskschedualer to run even if the user is logged off. This was not the case before, but my user account get changed I think, running with admin rights now.

jwijffels commented 6 years ago

For user logged off, have you tried https://github.com/bnosac/taskscheduleR/issues/44

rluech commented 6 years ago

sorry havent seen that, its written in your documentation. Yes I guesst that's it.

rluech commented 6 years ago

Ok, the taskscheduler now runs as intended, from Mo to Fr omitting Sa/So. Thanks!