How to Schedule & Automate R-Scripts | Windows

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey guys so today i'll be showing you guys how to automate our scripts on a windows system so we'll start off with our r script here i'm going to set my working directory so i'm just going to copy the path these should be forward slashes alright so the next step is to actually install the packages you are going to need for the script and i'm going to set my library path by calling dot lib paths one and then i'll actually install the packages here we need to set our repost location depending on your location and then lib it's just going to be our library path after we install the packages we're going to call them in and now we can begin our script all right so for the script i just want to get historical data so we'll test this out and then i'm just going to write the data out i'm going to use write zoo stock file you have to enter the full path so here we'll just name it spy dot csv so here we'll just run this we'll take a look at the working directory i'm going to try to enter a delimiter by running sep comma we'll go ahead and rerun this let's take a look at the data now it's formatted the way i want so now that we know that our script actually works we can go ahead and schedule a task to run this automatically but first go ahead and call notepad here i'm going to write the instructions so i'm going to start by doing that hit go off c drive path so here we need to enter the path of where r is located at so for most people it'll be c program files go to r and then we'll use the latest version then it'll be bin and then x64 so we essentially we're going to be calling our script here but we need to set the path to where it's located at so i'll go ahead and copy this then we need to set the current directory to where your r script is located then we need to call our script and then your file name and then after that's done running i'm going to do pause so we'll go ahead and save this has a bat file all right so close this out we're gonna have to go to task scheduler and then we're gonna go to create a task here you'll set the name for triggers we're gonna do new i want this to run weekly every monday tuesday wednesday thursday and friday and then we'll start it for tomorrow after the market closes and we'll give it a 15-minute break to let the data actually upload so i'll leave these as default then we'll go to actions we'll click on new if we want to start a program so here we have to search for our bat file hit open hit okay we'll check conditions we'll leave these as default settings we will leave these as default so we'll hit ok and now it's set to run for tomorrow so here we see all of our scripts and i guess we could go ahead and test it out by right clicking and then hit run so this is what it looked like every time it runs so it's done running it says press any key to continue i guess we could add some lines here that so that we know that it's actually running now let's try rerunning it so it was fairly quick here we see our now getting data now writing data and then it's done all right guys so that's pretty much it for this video it's fairly simple to schedule and automates in our script just make sure you require all the packages you're gonna need or else it'll break and that you use full path things let me know if you have any questions thanks for watching and i'll see you guys in the next video
Info
Channel: JasonR
Views: 4,327
Rating: 5 out of 5
Keywords: RStudio, RScript, Rprogramming, Task Scheduler, Automating Scripts, Automate Programming Scripts, Windows Task Scheduler
Id: V6oyhDS4FEs
Channel Id: undefined
Length: 8min 3sec (483 seconds)
Published: Tue Aug 04 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.