Scheduler to run a R script (windows)

It wasn’t possible to run some piece of code again and again. Hence, I decided to use a windows scheduler which would run a chunk of code at regular time intervals. Basically for my R file, I created a batch (.bat) file and we tell the scheduler to run that batch file at specific time or specific time interval. I have a windows system so this process is possible only on windows system. For linux systems we can use chron jobs to schedule

How to create batch file:-

  • Keep the entire code in one .R file
  • Go to the same folder, open a new text file.
  • Give the path of R executable followed by CMD BATCH and name of your R file

For me the line which I added was

"C:\Program Files\R\R-3.2.2\bin\R.exe" CMD BATCH TwitterBot.R
  • Save this text file and close it
  • Rename the text file from .txt extension to .bat. So previously, the text file was TwitterBot.txt in which I added the above line of code and later saved it as TwitterBot.bat


How to create a windows task scheduler:-

  • Search for windows task scheduler
  • Give some name to the task we want to create


  • Go to the triggers tab, click on New


  • Give the starting date and time and in advanced setting give the time duration after which we want to repeat the task. (I have selected it as 15 mins). Click on OK.
  • Next go to the Actions tab and then you can select the batch file to be run according to the schedule we created in the previous tab.


  • Click on OK and this should be it. It would start working immediately.
  • We can go back and edit the same parameters if we need to change any thing.

One thought on “Scheduler to run a R script (windows)

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s