I am working with the R programming language.
I am interested in learning how to schedule jobs in R - for instance, suppose I want to run the script below every Monday at 12:00 AM:
#my_script (create some random numbers, put them in a data frame,
and save this data frame as a "csv" file containing the date/time at which the file was created at):
a = rnorm(100,10,10)
b = rnorm(100,10,10)
my_data = data.frame(a,b)
write.csv(my_data, paste0("my_data", format(Sys.time(), "%d-%b-%Y %H.%M"), ".csv"))
#END
Reading on the internet, I found out two ways of doing this:
1) First Way:
Using the recently developed "taskscheduleR" package in R (taskscheduleR), you can specify which scripts and at what frequency you would like them to be scheduled:
#save the above script as an R file (I am not sure what "extdata" is)
myscript <- system.file("extdata", "my_script.R", package = "taskscheduleR")
## Run every week on Saturday and Sunday at 09:10
taskscheduler_create(taskname = "myfancyscript_sunsat", rscript = myscript,
schedule = "WEEKLY", starttime = "09:10", days = c('SUN', 'SAT'))
2) Second Way:
Jobs can also be scheduled using the "Windows Task Scheduler" - this can be seen over here: Scheduling R Script
My Question: Is it possible to do this ENTIRELY in Base R? That is, can this be done without directly using "Windows Task Scheduler" ?
For instance, suppose I save the above script as an "R file":
Using only commands in Base R, is it possible to specify how often you want to run this script and then send this script to the "task scheduler" - only using commands in Base R?
Can someone please show me how to do this?
Thanks!