I want to schedule an R script to run daily on a virtual machine. The script connects to a DWH, downloads data and generates a .CSV file in the same folder.
First, I installed R and Rstudio on virtual machine, ran my script manually and everything worked as expected.
Next, I used taskcheduleR package and scheduled the job. When the script runs, instead of generating the CSV with the data, it generates a .log file that contains the following text:
Error in file(file, ifelse(append, "a", "w")) :cannot open the connection
Calls: write.csv -> eval.parent -> eval -> eval -> write.table -> file
In addition: Warning message:
In file(file, ifelse(append, "a", "w")) : cannot open file 'Test.csv':
Permission denied
Execution halted
I solved it by doing the following:
Opened Rstudio as administrator and then scheduled the script via taskscheduler
Specified the folder of CSV output by using //
so like write.csv(DF, file = "C://Users//myusername//Desktop//myscripts//Test.csv")