Visualising scheduled tasks on Windows with R

I do most of my work on Windows 10, with the usual terminal sessions via SSH to Linux or VirtualBox VM for Ubuntu. Quite often though I have need to have tasks run automatically on my machine while I’m testing them before integrating into larger production deployments. A great tool is the taskscheduleR add-in for R Studio. It provides a very simple interface to the Windows’ 10 Task Scheduler (which is like cron) —

Schedule R scripts/processes with the Windows task scheduler. This allows R users to automate R processes on specific timepoints from R itself. The package is basically a wrapper around the Schtasks.exe functionality. More information about schtasks can be found at https://msdn.microsoft.com/en-us/library/windows/desktop/bb736357 or at the doc folder inside this package.

You can find out much more about it at the GitHub page here https://github.com/bnosac/taskscheduleR

What is really useful though is by calling the library underpinning the R Studio add-in, and with a few lines of R code, it is possible to create a simple but easy to view chart of when various R scripts will be executed —

library(tidyverse)
library(taskscheduleR)
library(janitor)
library(lubridate)
taskscheduler_ls() %>%
as_tibble() %>%
clean_names() %>%
mutate(next_run_time = dmy_hms(next_run_time)) %>%
filter(author == “<<put the author name here>>) %>%
arrange(desc(next_run_time)) %>%
mutate(task_name = factor(task_name, levels = unique(task_name))) %>%
ggplot(aes(next_run_time, task_name)) +
geom_point()

What this does is

  • use the taskscheduler_ls function to list all of the scheduled tasks
  • convert to a data frame
  • clean up the names using Janitor
  • cast the next run time to a date-time object
  • filter by the author, in this case replace with your own value
  • sort by next run time
  • mutate the task name to use factors
  • plot a scatter plot

This ends up looking like the below, although I’ve removed the script names for privacy reasons.

It just gives a very simple way to see when your script is going to run next.