bnosac / taskscheduleR

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

Having trouble removing an existing task #70

Closed pinkumbrella14 closed 4 years ago

pinkumbrella14 commented 4 years ago

I had scheduled a recurring daily task with taskcheduler_create, which was running dialy; however, my compter was restarted due to updates and I am now encountering an issue trying to reset this task.

Here is my code, which before the restart worked without issues:

library(taskscheduleR)

taskscheduler_delete("IA_run_daily")

myscript <- file.path("C:", "Users", "XXXXX", "Documents", "task_scheduler_rscripts", "forecast_IA_final.R")
cat(readLines(myscript), sep = "\n")
taskscheduler_create(taskname = "IA_run_daily", rscript = myscript, schedule = "DAILY",
                     starttime = "09:50", startdate = format(Sys.Date(), "%m/%d/%Y"))

When I run this script now, I get the following warning and the task will not run: [1] "WARNING: The task name \"IA_run_daily\" already exists. Do you want to replace it (Y/N)? " attr(,"status") [1] 1 Warning message: In system(cmd, intern = TRUE) : running command 'schtasks /Create /TN "IA_run_daily" /TR "cmd /c C:/Users/XXXX/AppData/Local/CONTIN~1/ANACON~1/lib/R/bin/Rscript.exe \"C:/Users/XXXX/Documents/task_scheduler_rscripts/forecast_IA_final.R\" >> \"C:/Users/XXXX/Documents/task_scheduler_rscripts/forecast_IA_final.log\" 2>&1" /SC DAILY /ST 09:50 /SD "12/12/2019" ' had status 1

I am not sure how to tell R that yes, I was to replace the previous "IA_run_daily" task with the current one I am trying to schedule. If I type "Y" into the console, I get an error "object not found". Would appreciate any thoughts on this!

jwijffels commented 4 years ago

Delete it first with taskscheduler_delete, next recreate it with taskscheduler_create. If your stuck, just go to the Windows Task scheduler and delete it there.

pinkumbrella14 commented 4 years ago

@jwijffels thanks. Honestly, I just realized that I didn't log in to RStudio as an administrator, which is why it wasn't giving me permission to change an existing task. Sorry, I'll close this issue! (Would delete it if I could).