4

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 = " ")
TylerH
  • 20,799
  • 66
  • 75
  • 101
Helio Roots
  • 177
  • 2
  • 10

1 Answers1

6

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.

Karsten W.
  • 17,826
  • 11
  • 69
  • 103
  • Why the code format is "format(Sys.Date()+1" ? I didn't understand this part of the code. – Helio Roots Jun 22 '17 at 17:30
  • Sys.Date() is today, Sys.Date()+1 is tomorrow. So the script is first executed tomorrow morning 9:10. `format` converts a Date object to a character. – Karsten W. Jun 23 '17 at 16:02