0

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
Phil
  • 7,287
  • 3
  • 36
  • 66
nba2020
  • 618
  • 1
  • 8
  • 22

2 Answers2

2

Sounds like a user permissions issue. Most likely, the user that runs Rstudio Server does not have write access on your virtual machine. When you run the script manually, are you logged in as the same user which executes the task scheduler script?

For example, on my remote Shiny Server, the user implementing the scripts is called 'shiny' by default. Hence, I have to give the 'shiny' user rwx permissions to the script directory.

Edit: Of course, you can add the scheduling through a system cron job (or eqv) outside of the Rstudio environment. On Linux, assuming that the cron user has rwx permissions in the directory:

Rscript /path/to/script.R
JDG
  • 1,342
  • 8
  • 18
0

I solved it by doing the following:

  1. Opened Rstudio as administrator and then scheduled the script via taskscheduler

  2. Specified the folder of CSV output by using // so like write.csv(DF, file = "C://Users//myusername//Desktop//myscripts//Test.csv")

nba2020
  • 618
  • 1
  • 8
  • 22