R/sys_time_print.R

Defines functions sys_time_print

Documented in sys_time_print

#' @title Convenient print of time taken
#' @description Convenient printing of time elapsed. A wrapper of
#' \code{data.table::timetaken}, but showing the results more directly.
#' @param expr Valid R expression to be timed.
#' @return A character vector of the form HH:MM:SS,
#' or SS.MMMsec if under 60 seconds. See examples.
#' @seealso \code{\link[data.table]{timetaken}}, \code{\link[base]{system.time}}
#' @examples
#'
#' sys_time_print(Sys.sleep(1))
#'
#' a = as.data.table(iris)
#' sys_time_print({
#'   res = a %>%
#'     mutate(one = 1)
#' })
#' res
#' @export

sys_time_print = function(expr){
  started.at=proc.time()
  eval(substitute(expr),envir = parent.frame())
  paste("Finished in",timetaken(started.at))
}

Try the tidyft package in your browser

Any scripts or data that you put into this service are public.

tidyft documentation built on April 14, 2020, 7:10 p.m.