Created
November 16, 2011 18:27
-
-
Save halpo/1370892 to your computer and use it in GitHub Desktop.
Time formatting for proc_time in R
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#' formats proc_time as a "hh:mm:ss" time string | |
#' | |
#' @seeAlso print.proc_time, proc.time | |
#' | |
formatTime <- function(x){ | |
stopifnot(inherits(x, "proc_time")) | |
h <- x %/% 3600L | |
m <- (x %% 3600L) %/% 60L | |
s <- x %% 60L | |
ifelse(is.na(x), NA, sprintf("%02d:%02d:%2.2f",h,m,s)) | |
} | |
#' Prints out time in an intelligent manner. | |
#' | |
#' @seealso system.time proc.time | |
#' @export | |
#' | |
print.proc_time<-function(x,...){ | |
times <- formatTime(x) | |
names(times) <- names(x) | |
print(times[!is.na(times)], ...) | |
invisible(x) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment