├── .gitignore ├── README.md ├── apple_microsoft.Rmd ├── command line.R ├── task.R └── task.bat /.gitignore: -------------------------------------------------------------------------------- 1 | .Rproj.user 2 | .Rhistory 3 | .RData 4 | Make_Task.Rproj 5 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Make_Task 2 | A Minimal Example for Scheduling Windows Tasks with R 3 | 4 | Also see: 5 | - [Blog Post](https://trinkerrstuff.wordpress.com/2015/02/11/scheduling-r-tasks-via-windows-task-scheduler/) 6 | - [Video](https://www.youtube.com/watch?v=UDKy5_SQy2o) 7 | 8 | 9 | ### Update 10 | 11 | Using... 12 | 13 | ``` 14 | @echo off 15 | R CMD BATCH C:\Users\Tyler\Desktop\Make_Task\task.R 16 | ``` 17 | 18 | makes strong assumptions about where R is located and if it's on the user's path. As [@apwheele](https://trinkerrstuff.wordpress.com/2015/02/11/scheduling-r-tasks-via-windows-task-scheduler/#comment-1553) points out using the full path name to run a [batch file](http://www.statmethods.net/interface/batch.html) is more reliable. 19 | ``` 20 | @echo off 21 | "C:\R\R-3.2.2\bin\x64\R.exe" CMD BATCH C:\Users\Tyler\Desktop\Make_Task\task.R 22 | ``` 23 | 24 | If the path of your R file has spaces in it, make sure to enclose the path in quotes otherwise the code won't run: 25 | ``` 26 | @echo off 27 | "C:\R\R-3.2.2\bin\x64\R.exe" CMD BATCH "C:\Users\Tyler\Desktop\Some Other Path\task.R" 28 | ``` 29 | -------------------------------------------------------------------------------- /apple_microsoft.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Apple and Microsoft Report" 3 | date: "`r format(Sys.time(), '%d %B, %Y')`" 4 | output: 5 | pdf_document: 6 | toc: true 7 | number_sections: true 8 | --- 9 | 10 | ```{r, echo=FALSE,message=FALSE} 11 | pacman::p_load(quantmod) 12 | invisible(getSymbols(c('AAPL', 'MSFT'))) 13 | invisible(dev.off()) 14 | ``` 15 | 16 | ```{r, echo=FALSE} 17 | chartSeries(AAPL, theme="white", type="candlestick", TA=c(addVo(),addBBands())) 18 | invisible(dev.off()) 19 | chartSeries(MSFT, theme="white", type="candlestick", TA=c(addVo(),addBBands())) 20 | invisible(dev.off()) 21 | ``` -------------------------------------------------------------------------------- /command line.R: -------------------------------------------------------------------------------- 1 | recurrence <- "once" 2 | task_name <- "MyTask" 3 | bat_loc <- "C:\\Users\\Tyler\\Desktop\\Make_Task\\task.bat" 4 | time <- "00:21" 5 | 6 | system(sprintf("schtasks /create /sc %s /tn %s /tr \"%s\" /st %s", recurrence, task_name, bat_loc, time)) 7 | 8 | 9 | ## Additional arguments 10 | browseURL("https://msdn.microsoft.com/en-us/library/windows/desktop/bb736357%28v=vs.85%29.aspx") 11 | 12 | ## Open the scheduled tasks 13 | system("control schedtasks") 14 | -------------------------------------------------------------------------------- /task.R: -------------------------------------------------------------------------------- 1 | if (!"pacman" %in% dir(.libPaths())) devtools::install_github("trinker/pacman") 2 | pacman::p_load(rmarkdown, knitr) 3 | pacman::p_load_gh("trinker/gmailR") 4 | 5 | ## This will need to be changed to your local settings 6 | setwd("C:/Users/Tyler/Desktop/Make_Task") 7 | 8 | unlink("reports", recursive = TRUE, force = FALSE) 9 | 10 | rmarkdown::render("apple_microsoft.Rmd", "all", output_dir = "reports") 11 | 12 | gmailR::gmail( 13 | to="tyler_rinker@hotmail.com", 14 | subject = "Stock Reports", 15 | password = "PASSWORD", 16 | message = "Please find the attached stock report.", 17 | attachment = "reports/apple_microsoft.pdf", 18 | username = "YOU_SOMEPLACE@gmail.com" 19 | ) 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /task.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | R CMD BATCH C:\Users\Tyler\Desktop\Make_Task\task.R --------------------------------------------------------------------------------