Learn R Programming

runjags (version 2.0.3-2)

timestring: Calculate the Elapsed Time in Sensible Units

Description

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.

Usage

timestring(time1, time2=NA, units=NA, show.units=TRUE)

Arguments

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.

Value

See Also

Sys.time

Examples

Run this code

# 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)

Run the code above in your browser using DataLab