Search code examples
rwindows-task-scheduler

Scheduling R scripts in Task Scheduler - CMD runs, but task does not complete


I am trying to automate R scripts in Windows Task Scheduler. I've finally managed to get the program to run, sort of, but it doesn't complete its task.

When task scheduler runs, the CMD windows pops up and I can see it installing the necessary packages to run the script, but the task doesn't actually complete. It is supposed to update a spreadsheet, which works when I run the script in R Studio but does not work when I run it through Task Scheduler.

I am running the script through Windows Task Scheduler as follows:

Action: Start a Program

Program/script:"C:\R-4.0.3\bin\Rscript.exe"

Add arguments: "C:\Documents\Options-Measurement.R"


Solution

  • This may be related to the working directory. Could you please add something like print(getwd()) to your script and check if it is the desired working directory?