0

I wanted to use a Windows .bat file to run several R scripts and schedule it using windows scheduler.

However, when I test using windows scheduler, everything executes but the files that the R scripts should create are never created. Instead, when I double-click on the .bat file itself it works fine. My goal is for several scripts to just run overnight without me going in and running each one of them manually one-by-one.

If I were to add a second line to the .bat file that would make it run a second script, would this execute only after the first is complete? If not, would I be able to delay the second until the first finishes somehow?? For instance, my .bat file looks like this:

 "C:\Program Files\R\R-3.4.2\bin\x64\R.exe" CMD BATCH C:\Users\gma\Desktop\R_Task\script1.R 
 "C:\Program Files\R\R-3.4.2\bin\x64\R.exe" CMD BATCH C:\Users\gma\Desktop\R_Task\script2.R 

I used the answer provided by @Gautam (R taskscheduleR not executing script) to get this far

Spencer K
  • 73
  • 5
  • What do you see in `script1.Rout` and `script2.Rout`? – user2554330 Oct 04 '22 at 16:54
  • Hello @user2554330 , sorry for the late reply. script1.R writes the phrase "Hello World" to a .csv file script2.R writes the phrase "Hello World, again" to a second .csv file script1.Rout and script2.Rout both say the following: Error in file(file, ifelse(append, "a", "w")) : cannot open the connection Calls: write -> cat -> file In addition: Warning message: In file(file, ifelse(append, "a", "w")) : cannot open file 'script1.csv': Permission denied Execution halted – Spencer K Oct 05 '22 at 21:00
  • 1
    Two possibilities: 1. There's a permissions issue because whatever user is used by the scheduler doesn't have permission to write in the location you specified. 2. The current directory isn't what you expected when writing, so the path to the file doesn't work. A relative path (e.g. `"output/script1.csv"`) won't work unless the path `"output"` already exists in the current working directory. – user2554330 Oct 06 '22 at 09:15

0 Answers0