0

I need to schedule the following R script:

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

I want to do it with the R Packahe "taskscheduleR", and I made the syntax:

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 successfully created. But, when we arrive at 06:00 it seems that the MyScript.R doesn't run, because the mydata.txt in not produced in the C:/Andrea/R/ folder.

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

taskscheduler_delete(taskname="mytask")

But it says: Access Denied.

Could you help me please to solve it, please?

TylerH
  • 20,799
  • 66
  • 75
  • 101
user1010441
  • 59
  • 1
  • 7

1 Answers1

0

An alternative, perhaps not the best, approach may be:
Not using taskscheduleR, please consider my batch command to run an R script requires the specific program to run and command line parameters.

toptwenty.bat file:

@echo off "C:\Program Files\R\R-3.2.3\bin\i386\R.exe" CMD BATCH "H:\rProj\top20\fillTopTwenty.R"

My scheduled task as viewed in Windows Task Scheduler, set up manually, calls this batch file.

Ben Jacobson
  • 83
  • 1
  • 9