<p><div><div><div><div data-width="100" data-show-faces="false" data-send="true" data-layout="button_count" data-height="21" data-href="http://www.r-bloggers.com/track-your-local-r-scheduled-tasks-with-commandcenter2000/"></div></div><div><a data-url="http://www.r-bloggers.com/track-your-local-r-scheduled-tasks-with-commandcenter2000/" data-counturl="http://www.r-bloggers.com/track-your-local-r-scheduled-tasks-with-commandcenter2000/" data-count="horizontal" data-text="Track your local R scheduled tasks with CommandCenter2000!!!" class="twitter-share-button" data-via="rbloggers" href="https://twitter.com/share"></a></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://amitkohli.com/track-your-local-r-scheduled-tasks-with-commandcenter2000/"> R – AmitKohli.com</a></strong>, and kindly contributed to <a rel="nofollow" href="http://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>There are many ways to automate your scripts running, for example using RScript, or <a target="_blank" href="http://www.r-bloggers.com/taskscheduler-r-package-to-schedule-r-scripts-with-the-windows-task-manager/?utm_source=feedburner&utm_medium=email&utm_campaign=Feed%3A+RBloggers+%28R+bloggers%29">in-R itself</a> (and now even as an <a target="_blank" href="http://www.bnosac.be/index.php/blog/57-new-rstudio-add-in-to-schedule-r-scripts">add-in</a> for RStudio) (<a target="_blank" href="http://www.r-bloggers.com/?s=schedule">check all here</a>). But after a while, it can get a bit overwhelming to track tasks and ensure they are firing as planned. In order to address this, I have developed some futuristic advanced tech that lets us do that. I hereby present to you: the CommandCenter2000!!! Yes, it’s Y2K compliant! This is what it looks like:</p>
<p> </p>
<p><a target="_blank" href="http://i0.wp.com/amitkohli.com/wp-content/uploads/2016/05/Capture.png"><img sizes="(max-width: 300px) 100vw, 300px" srcset="http://i0.wp.com/amitkohli.com/wp-content/uploads/2016/05/Capture.png?resize=300%2C166 300w, http://i0.wp.com/amitkohli.com/wp-content/uploads/2016/05/Capture.png?w=471 471w" alt="Capture" class="wp-image-658" src="http://i0.wp.com/amitkohli.com/wp-content/uploads/2016/05/Capture.png?resize=300%2C166" data-recalc-dims="1"></a></p>
<p> </p>
<p>It has the following features:</p>
<ul>
<li>It’ll tell you when the script ran last</li>
<li>whether it was successful or not (green/red light)</li>
<li>and will help you rerun failed scripts in 2 ways.</li>
</ul>
<h2>How to make your own:</h2>
<p><a target="_blank" href="http://i2.wp.com/amitkohli.com/wp-content/uploads/2016/05/diagram-1.png"><img sizes="(max-width: 300px) 100vw, 300px" srcset="http://i2.wp.com/amitkohli.com/wp-content/uploads/2016/05/diagram-1.png?resize=300%2C230 300w, http://i2.wp.com/amitkohli.com/wp-content/uploads/2016/05/diagram-1.png?resize=768%2C588 768w, http://i2.wp.com/amitkohli.com/wp-content/uploads/2016/05/diagram-1.png?w=847 847w" alt="diagram" class="wp-image-674" src="http://i2.wp.com/amitkohli.com/wp-content/uploads/2016/05/diagram-1.png?resize=300%2C230" data-recalc-dims="1"></a></p>
<p>(Follow the steps in the schematic above: red for setup, and yellow to run it. These are explained below)</p>
<ol>
<ol>
<li>Setup the folders where there are running tasks. Concretely, inside the working folder for each script, you need a .bat file that will run that specific script. Within the bat file<span>*</span>, the code will look like this for example:
<p><code>@echo off<br>
&quot;C:Program FilesRR-3.2.2binx64R.exe&quot; --vanilla --slave CMD BATCH &quot;D:Project Xanalyzer.R&quot;<br>
</code></p>
</li>
<li>OK, now you need to schedule the task in Windows (I like scheduling it myself so that I can set some specific requirements… in particular, I want tasks to fire only if connected to certain wifi). Don’t know how to do this? <a target="_blank" href="https://trinkerrstuff.wordpress.com/2015/02/11/scheduling-r-tasks-via-windows-task-scheduler/">Check this out </a>(that’s how I learned)!</li>
<li>OK, now tasks will be firing off! Now you need to get the command Center script from my<a target="_blank" href="https://github.com/mexindian/CommandCenter"> github account</a>. Go<br>
<br>
<iframe height="20px" width="80px" src="https://ghbtns.com/github-btn.html?user=mexindian&repo=CommandCenter&type=fork&count=true"></iframe><br>
it now!
<ol>
<li>This contains:
<ol>
<li>the CommandCenter R script</li>
<li>a .bat file that will run the CommandCenter2000!!! itself. I recommend creating a shortcut to this bat file on your desktop or whatever. That way you can run it whenever</li>
<li>the html file that reports the status of each task.</li>
<li>ignore the rest of the stuff</li>
</ol>
</li>
<li>Ok, now you have a local CommandCenter2000!!!.
<ol>
<li>Set up the WORKING DIRECTORY to wherever you installed the folder.</li>
<li>Now, for each script you’d like to track in the CommandCenter2000!!!, add a reference to that script in the main CommandCenter2000!!! script. By “reference”, I mean:
<ol>
<li>Copy the block of code that looks like it should be copied. (hint, there’s START and END comments). Within each:
<ol>
<li>Give that script a human name (this is what will be displayed)</li>
<li>Specify the path and name of the R file (remember the whole “/” vs “” debacle for windows paths)</li>
<li>Specify the path and name of  the .bat file</li>
</ol>
</li>
<li>That’s it! Rinse and repeat for every script that you would like on your CommandCenter2000!!!</li>
</ol>
</li>
</ol>
</li>
</ol>
</li>
<li>OK, setup is done. Now, whenever you want to check the status of scripts, you can just run your command center. Of course, you <em>could</em> run the CommandCenter2000!!! itself on a schedule… but putting something on a schedule to check whether other things are running on schedule correctly is a bit…… mind-bending. Careful you don’t <a target="_blank" href="https://xkcd.com/1638/">break reality.</a></li>
<li>Everytime you click it, you’ll get the html file coming up shown above. In detail:
<ol>
<li>“<strong>thing</strong>“: is just the name of the analysis</li>
<li>“<strong>lastRun</strong>“: is how long ago the analysis ran (in days… although obviously this is configurable).</li>
<li>“<strong>status</strong>“: (this is the last column) has a red or green light to indicate whether the script ran successfully or not. If it didn’t, the red light will have  a mouseover effect whereby you’ll be able to tell what the error was…. which looks like this: <a target="_blank" href="http://i0.wp.com/amitkohli.com/wp-content/uploads/2016/05/dd.png"><img sizes="(max-width: 300px) 100vw, 300px" srcset="http://i0.wp.com/amitkohli.com/wp-content/uploads/2016/05/dd.png?resize=300%2C29 300w, http://i0.wp.com/amitkohli.com/wp-content/uploads/2016/05/dd.png?resize=768%2C74 768w, http://i0.wp.com/amitkohli.com/wp-content/uploads/2016/05/dd.png?resize=1024%2C98 1024w, http://i0.wp.com/amitkohli.com/wp-content/uploads/2016/05/dd.png?w=1076 1076w" alt="dd" class="wp-image-666" src="http://i0.wp.com/amitkohli.com/wp-content/uploads/2016/05/dd.png?resize=300%2C29" data-recalc-dims="1"></a>This mouseover effect will help you debug… using the following two options</li>
<li>“<strong>SomethingWrong</strong>“: provides a link to the R file, <span>in case the script failed because your R script is messed up</span>. Don’t click the link, but right click and “copy link”, then open it from R (sorry for roundabout way, but unfortunately it’s very difficult to launch a local file from HTML for security)</li>
<li>“<strong>runLink</strong>: provides a link to the bat file that will run the script (more on this later). Use this<span> if  the script failed but you think the R script is correct and just needs to rerun</span> (for example if the network crapped out), just click, download the bat file and run it… everything will rerun automatically.</li>
</ol>
</li>
</ol>
</ol>
<p> </p>
<p>So clearly, this is a very rough first-pass attempt to keep track of scheduled tasks. If you’d like to collaborate, I’d love to evaluate some pull-requests.</p>
<p> </p>
<p> </p>
<p><span>*WARNING: This approach uses .bat files, which could damage your computer or corrupt your data. Be VERY CAREFUL, and don’t trust anybody else’s bat files without first examining them in a text editor.</span></p>
<p><div><div><div><div data-width="55" data-show-faces="false" data-send="true" data-layout="box_count" data-height="62" data-href="http://www.r-bloggers.com/track-your-local-r-scheduled-tasks-with-commandcenter2000/"></div></div><div><a data-url="http://www.r-bloggers.com/track-your-local-r-scheduled-tasks-with-commandcenter2000/" data-counturl="http://www.r-bloggers.com/track-your-local-r-scheduled-tasks-with-commandcenter2000/" data-count="vertical" data-text="Track your local R scheduled tasks with CommandCenter2000!!!" class="twitter-share-button" data-via="rbloggers" href="https://twitter.com/share"></a></div><div></div></div><div></div></div>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="http://amitkohli.com/track-your-local-r-scheduled-tasks-with-commandcenter2000/"> R – AmitKohli.com</a></strong>.</div>
<hr>
<a rel="nofollow" href="http://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="http://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a title="The R Project for Statistical Computing" rel="nofollow" href="http://www.r-project.org/">R</a> news and <a title="R tutorials" rel="nofollow" href="http://www.r-bloggers.com/?s=tutorial">tutorials</a> on topics such as: <a title="Data science" rel="nofollow" href="http://www.r-bloggers.com/?s=data%20science">Data science</a>, <a title="Big Data" rel="nofollow" href="http://www.r-bloggers.com/?s=Big%20Data">Big Data, <a title="R jobs" rel="nofollow" href="http://www.r-users.com/">R jobs</a>, visualization (<a title="ggplot and ggplot2 tutorials" rel="nofollow" href="http://www.r-bloggers.com/?s=ggplot2">ggplot2</a>, <a title="Boxplots using lattice and ggplot2 tutorials" rel="nofollow" href="http://www.r-bloggers.com/?s=boxplot">Boxplots</a>, <a title="Maps and gis" rel="nofollow" href="http://www.r-bloggers.com/?s=map">maps</a>, <a title="Animation in R" rel="nofollow" href="http://www.r-bloggers.com/?s=animation">animation</a>), programming (<a title="RStudio IDE for R" rel="nofollow" href="http://www.r-bloggers.com/?s=RStudio">RStudio</a>, <a title="Sweave and literate programming" rel="nofollow" href="http://www.r-bloggers.com/?s=sweave">Sweave</a>, <a title="LaTeX in R" rel="nofollow" href="http://www.r-bloggers.com/?s=LaTeX">LaTeX</a>, <a title="SQL and databases" rel="nofollow" href="http://www.r-bloggers.com/?s=SQL">SQL</a>, <a title="Eclipse IDE for R" rel="nofollow" href="http://www.r-bloggers.com/?s=eclipse">Eclipse</a>, <a title="git and github, Version Control System" rel="nofollow" href="http://www.r-bloggers.com/?s=git">git</a>, <a title="Large data in R using Hadoop" rel="nofollow" href="http://www.r-bloggers.com/?s=hadoop">hadoop</a>, <a title="Web Scraping of google, facebook, yahoo, twitter and more using R" rel="nofollow" href="http://www.r-bloggers.com/?s=Web+Scraping">Web Scraping</a>) statistics (<a title="Regressions and ANOVA analysis tutorials" rel="nofollow" href="http://www.r-bloggers.com/?s=regression">regression</a>, <a title="principal component analysis tutorial" rel="nofollow" href="http://www.r-bloggers.com/?s=PCA">PCA</a>, <a title="Time series" rel="nofollow" href="http://www.r-bloggers.com/?s=time+series">time series</a>, <a title="finance trading" rel="nofollow" href="http://www.r-bloggers.com/?s=trading">trading</a>) and more...
<img height="1" alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/B9iZsnIeonc"></a></div>