How to automate a script in R using taskscheduleR?

743 Views Asked by At

I am currently looking at this documentation to automate a script on my machine using R and taskscheduleR. I am confused within this documentation of the following:

In the example within the documentation, what is "extdata", is this supposed to be the file path of my R script and is "helloworld.R" the actual R script?

myscript <- system.file("extdata", "helloworld.R", package = "taskscheduleR")

My current take at this is below: Where C:/Users/santi/Documents/R Scripts is my file path and Wayerhaeuser_Automation_script.R is my actual R script

myscript <- system.file("C:/Users/santi/Documents/R Scripts", "Wayerhaeuser_Automation_script.R", package = "taskscheduleR")

taskscheduler_create(taskname = "myfancyscript", rscript = myscript, 
                     schedule = "ONCE", starttime = format(Sys.time() + 62, "%H:%M"))

I was a bit confused on the documentation of it.

Attempt after trying proposed solution: enter image description here

1

There are 1 best solutions below

4
On

Change myscript to:

myscript <- paste0("C:/Users/santi/Documents/R Scripts/","Wayerhaeuser_Automation_script.R")

and it should work just fine. The rscript argument is just a string path to the file to run. Sometimes paths are interpreted improperly if there are spaces, so if it doesn't work, also try changing the folder name to R_Scripts