| 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] (ORCID: <https://orcid.org/0000-0002-7683-4592>), Poisson Consulting [fnd, cph] |
| Maintainer: | Joe Thorley <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.0.1.9000 |
| Built: | 2026-05-23 19:17:05 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.
Timer$is_running()Timer$is_running()
Timer$elapsed()Timer$elapsed()
Timer$reset()Timer$reset()
Timer$start()Timer$start()
Timer$stop()Timer$stop()
Timer$clone()The objects of this class are cloneable with this method.
Timer$clone(deep = FALSE)
deepWhether 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()