When I schedule an R script using the taskschedulerR library, R is executed at C:/windows/system32 which screws up all the relative paths in my R Script. The script I am trying to run looks like this, and I am making use of the here package.
library('here') source(here::here('script1.R')) source(here::here('script2.R'))
This runs fine in RStudio.
I then use the library taskscheduleR, like so, to create a regular run of my main.R script.
taskscheduler_create(taskname = "my_main_script", rscript = here::here('main.R'), schedule = "MINUTE", starttime = '11:00', modifier = 30)
But in the log for this, I am given this error ....
Error in file(filename, "r", encoding = encoding) : cannot open the connection Calls: source -> file In addition: Warning message: In file(filename, "r", encoding = encoding) : cannot open file 'C:/Windows/System32/script1.R': No such file or directory Execution halted
I understand why this is happening, but am unsure of an elegant way to fix it. I don't want to hardcode the path of the files in the source command, as I am trying to design my code to be portable between different environments.
Thanks for any help you might be able to offer.