Calculate the Elapsed Time in Sensible Units
Function to calculate the elapsed time between 2 time periods (in seconds), or to calculate a number of seconds into a time measurement in more sensible units.
timestring(time1, time2 = NA, units = NA, show.units = TRUE)
time1 |
either the time index (from Sys.time()) at the start of the time period, a length of time in seconds, or an object of class 'difftime'. |
time2 |
either the time index (from Sys.time()) at the end of the time period, or missing data if converting a single length of time. Default NA. |
units |
either missing, in which case a sensible time unit is chosen automatically, or one of 's', 'm', 'h', 'd', 'w', 'y' to force a specific unit. Default NA. |
show.units |
if TRUE, then the time is returned with units, if FALSE then just an integer is returned. Default TRUE. |
A time measurement, with or without units.
# Time how long it takes to complete a task: pre.time <- Sys.time() Sys.sleep(2) # PROCESS TO TIME post.time <- Sys.time() timestring(pre.time, post.time) # Convert 4687 seconds into hours: timestring(4687, units='hours', show.units=FALSE)
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.