knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "README-"
)

R build status Codecov test coverage

timer

Introduction

An R package implementing 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.

Utilisation

library(timer)

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

Installation

To install from GitHub

# install.packages("devtools")
devtools::install_github("poissonconsulting/timer")

Contribution

Please report any issues.

Pull requests are always welcome.

Code of Conduct

Please note that the timer project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.



poissonconsulting/timer documentation built on Feb. 18, 2021, 11:17 p.m.