bnosac / taskscheduleR

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

simple r script not able to schedule #41

Closed andreaperlato closed 6 years ago

andreaperlato commented 6 years ago

Hi Jan, I have this simple script:

x0 = 5.9
a <- seq(x0, 6, 0.01)
b <- mean (a)
write.table(b, "C:/01 - Andrea/mydata.txt", sep="\t")

Scheduled with the following code:

library(taskscheduleR)
wma <- file.path("C:", "01 - Andrea", "myscript.R")
taskscheduler_create(taskname = "myscriptdaily", rscript = wma, 
                     schedule = "DAILY", starttime = "17:37", startdate = format(Sys.Date()+1, "%d/%m/%Y"))

Now, I am not using the computer of the Bank where I work, but I am using my personal computer. But still, I have problem: the mydata.txt is not produced.

Why?

Thanks? A

jwijffels commented 6 years ago

Is C:/01 - Andrea/myscript.log created?

andreaperlato commented 6 years ago

No, it is not procuced. A

jwijffels commented 6 years ago

Then it is not scheduled. Look at taskscheduler_ls() to see what you scheduled and make sure this works first with the correct date for your locale as specified in startdate (if your locale is day/month/year or month/day/year make sure you specify it correctly. Note that your startdate indicates that it will run starting from tomorrow, not today.

andreaperlato commented 6 years ago

Hi Jan, it dirve me crazy. mydate

My sys.date is exactely the same with what I used in the R script. And now, I scheduled today:

taskscheduler_create(taskname = "skd", rscript = wma, 
                     schedule = "DAILY", starttime = "20:03", 
                     startdate = format(Sys.Date(), "%d/%m/%Y"))

But again no log and .txt is produced....

jwijffels commented 6 years ago

Start with ONCE to see if your R code you want to schedule does not contains errors and you give the right path. Next take MINUTELY and try different formats format(Sys.Date(), "%d/%m/%Y"), format(Sys.Date(), "%m/%d/%Y"), format(Sys.Date(), "%Y/%m/%d"), and make sure if you schedule, you taskscheduler_delete the taskname. You should provide the output of taskscheduler_ls() for the taskname that you gave.

andreaperlato commented 6 years ago

Hi Jan, I just ran the same script of yesterday, without any sort of changes, and now incomprehensibly is working.

Thnak you for your help. Just last question: when I try to cancel a task with taskscheduler_delete(taskname = "mytask") Some time I receive: Warning message: running command 'schtasks /Delete /TN "A" /F' had status 1

What is this error?

Thank you, Andrea

jwijffels commented 6 years ago

Good that you solved it yourself. If you have other issues please provide a reproducible example and create a new issue if needed.