Description Usage Format Examples
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
.
1 |
An R6Class
generator object.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | # 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()
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.