Skip to content

Instantly share code, notes, and snippets.

@tonyelhabr
Created June 16, 2020 12:37
Show Gist options
  • Save tonyelhabr/07f64a93cccfd4dfd4f14df51f75af27 to your computer and use it in GitHub Desktop.
Save tonyelhabr/07f64a93cccfd4dfd4f14df51f75af27 to your computer and use it in GitHub Desktop.
Simple logic for pretty time-to-complete message
library(magrittr)
start <- Sys.time()
end <- Sys.time()
dur <- (end - start) %>% lubridate::as.duration()
dur_s <- round(as.numeric(dur, 'seconds'), 1) %>% scales::comma()
dur_m <- round(as.numeric(dur, 'minutes'), 1) %>% scales::comma()
cat(glue::glue('action took {dur_s} seconds ({dur_m} minutes) to complete.'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment