bnosac / taskscheduleR

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

How to use taskscheduleR #40

Closed andreaperlato closed 6 years ago

andreaperlato commented 6 years ago

Hi Jan, I am Andrea Perlato from Swizerland. Sorry if tI disturb you but I really need to schedule the following R script named MyScript.R:

remove(list=ls()) library(DBI) library(ROracle) drv <- dbDriver("Oracle") connection <- dbConnect(drv, username="**", password="**", dbname="name_of_db") mydata <- dbGetQuery(connection, " SELECT Var1, Var2, FROM Table WHERE Var3 = '123' ") write.table(mydata, "C:/Andrea/R/mydata.txt, sep="\t")

So, I just get data from Oracle, then I convert the result in .txt and save it in C:/Andrea/R. I want to run it every day at 06:00 am, in order to have the .txt updated everyday in C:/Andrea/R

So, I created the atsk with the following code:

library(taskscheduleR) wma <- file.path("C:", "Andrea","MyScript.R") taskscheduler_create(taskname="mytask"), rscript = wma, schedule = "DAILY", starttime="06:00", startdate=format(Sys.Date()+1. "%d/%m/%Y"))

So far so good: the "mytask" is sussessfull created. But, when arrive the 06:00 it seems that the MyScript.R doen't run, because the mydata.txt in not produced in the C:/Andrea/R/ folder.

Moreover, I tryed to cancel the mytask just created with:

taskscheduler_delete(taskname="mytask")

But it ays: Acess Deny.

Could you help me please to solve it. I really need to use the scheduleR.

Thank you, Kind regards, Andrea

jwijffels commented 6 years ago

This is not reproducible. Can you make it reproducible? If it is scheduled correctly for your case, the log should end up in c:/Andrea/MyScript.log

andreaperlato commented 6 years ago

Hi, Jan, thank you for your help. Yes, the log in not produced in the c:/Andrea/MyScript.log So, which is the problem with my script? Is it a problem with the rights of Schtasks.exe? If so, what I have to ask to my Administrator?

Thank you, Andrea

jwijffels commented 6 years ago

Your taskscheduler_create code has syntax errors. Ask your admin to have richts to on schtasks.exe

andreaperlato commented 6 years ago

Sorry Jan, but why did you close my question? Can you tell me where are the errors in my syntax, please?

What is a "richtsnoer"?

Thank you, A

jwijffels commented 6 years ago
taskscheduler_create(taskname="mytask", rscript = wma, schedule = "DAILY", starttime="06:00",
startdate=format(Sys.Date()+1. "%d/%m/%Y")