Skip to content

Instantly share code, notes, and snippets.

@Myfanwy
Created July 28, 2017 04:31
Show Gist options
  • Save Myfanwy/083d3200244b30e67e0edd1c38d6b09f to your computer and use it in GitHub Desktop.
Save Myfanwy/083d3200244b30e67e0edd1c38d6b09f to your computer and use it in GitHub Desktop.
Timer function for R
# Depends on the `beepr` package by @rasmusab: https://cran.r-project.org/web/packages/beepr/README.html
# Code greatly improved by flodel on Stack Exchange Code Review (thanks flodel)
# Planned improvements/expansions: new end-of-timer sounds, add functionality for starting a separate R session so that it doesn't bogart the current one.
timer <- function(interval, units = c("secs", "mins", "hours", "days", "weeks")) {
units <- match.arg(units)
num_sec <- interval * switch(units, secs = 1, mins = 60, hours = 3600,
days = 86400, weeks = 604800)
Sys.sleep(num_sec)
if (require(beepr)) beep(2) else message("TIMER DONE YO!")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment