Title: | R6 Timer |
---|---|
Description: | A simple timer as an R6 class. The timer has four functions: start(), stop(), reset() and elapsed(). The elapsed() function returns the elapsed wall clock time (as opposed to CPU time) as an object of class lubridate::Duration. |
Authors: | Joe Thorley [aut, cre] , Poisson Consulting [fnd, cph] |
Maintainer: | Joe Thorley <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.0.1.9000 |
Built: | 2024-11-21 06:38:03 UTC |
Source: | https://github.com/poissonconsulting/timer |
A simple timer as an R6 class.
The timer has four functions: $start()
, $stop()
, $reset()
and $elapsed()
.
The $elapsed()
function returns the elapsed wall clock time (as opposed to CPU time)
as an object of class lubridate::Duration
.
An R6Class
generator object.
is_running()
Timer$is_running()
elapsed()
Timer$elapsed()
reset()
Timer$reset()
start()
Timer$start()
stop()
Timer$stop()
clone()
The objects of this class are cloneable with this method.
Timer$clone(deep = FALSE)
deep
Whether to make a deep clone.
# instantiate a new timer timer <- Timer$new() # no time has elapsed because the timer has not started timer$elapsed() # start the timer timer$start() # get the time elapsed (as an object of class lubridate::Duration) # time elapsed is increasing because the timer is still running timer$elapsed() timer$elapsed() # stop the timer timer$stop() # time elapsed is now fixed timer$elapsed() timer$elapsed() # because timer is an object of class R6 use the clone() function # to make a copy timer2 <- timer$clone() # reset the timer timer$reset() timer$elapsed() # timer2 is not reset timer2$elapsed()
# instantiate a new timer timer <- Timer$new() # no time has elapsed because the timer has not started timer$elapsed() # start the timer timer$start() # get the time elapsed (as an object of class lubridate::Duration) # time elapsed is increasing because the timer is still running timer$elapsed() timer$elapsed() # stop the timer timer$stop() # time elapsed is now fixed timer$elapsed() timer$elapsed() # because timer is an object of class R6 use the clone() function # to make a copy timer2 <- timer$clone() # reset the timer timer$reset() timer$elapsed() # timer2 is not reset timer2$elapsed()