R taskscheduleR not recognizing rscript

1.9k Views Asked by At

I am trying to use the R's taskscheduleR package to download data using a script every tenth of a minute (every 6 seconds). To do this, I have a script named getwmatadata.R which downloads data from an API and I am trying to call this script using taskscheduleR based on the following link: https://github.com/bnosac/taskscheduleR

However, my script below is not working because I get an error saying

Error in taskscheduler_create(taskname = "wmatadata", rscript = wmatapinger, : File does not exist

Below is how I'm trying to run taskscheduleR:

library(taskscheduleR)
wmatapinger <- system.file("extdata", "getwmatadata.R", package = "taskscheduleR")
taskscheduler_create(taskname = "wmatadata", rscript = wmatapinger, schedule = "MINUTE", starttime = "05:00", modifier = 0.1)
4

There are 4 best solutions below

0
On

One possible solution and easy to implement -

library(taskschedulerR)
taskscheduler_create(taskname = "ABC",
                     rscript = Full Address of the 
                               script, 
                     schedule = "DAILY", 
                     starttime = "23:45", 
                     startdate = format(Sys.Date(), 
                                        "%d/%m/%Y"))
0
On

Just configure the path to your script using file.path() ... don't use system.file()

Solution:

wmatapinger <- file.path("C:", "name_of_the_folder", "wmatapinger.R")

Please refer to the file.path() how to construct the path (comma means forward slash / )

Your next line is fine and now it should work.

0
On

I was getting the same error. Although it took several attempts (I kept getting the error "file does not exist"), I was finally able to solve it by scheduling it via the GUI add-in.

If you're using RStudio, go to Tools → Addins → "Schedule R scripts on…". This eventually worked for me.

0
On

Check if your .R file exist on the path that you specified.

file.exists(wmatapinger)