Search code examples
rscheduled-tasksr-taskscheduler

How to run task scheduler everyday at the same time in R?


How can I set a script to run everyday automatically at 11:00pm?

I found the package "taskscheduleR", but I don't know how to run my script with it.

taskschedulerR exemple:

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

## run script once within 62 seconds taskscheduler_create(taskname = "myfancyscript", rscript = myscript, schedule = "ONCE", starttime = format(Sys.time() + 62, "%H:%M"))

My script

dayfile <- read.csv("A:/file_170611.txt", sep = " ", header=F, stringsAsFactors = F)
write.table(dayfile, file="A:/dayfiles/dayfile.txt", sep = " ")

Solution

  • The README of taskscheduleR looks quite on the point:

    library(taskscheduleR)
    myscript <- "A:/script.R" # path to script
    taskscheduler_create(taskname = "myscriptdaily", rscript = myscript, 
        schedule = "DAILY", starttime = "09:10", 
        startdate = format(Sys.Date()+1, "%d/%m/%Y")
    )
    

    and you are done.