diff --git a/index.html b/index.html index 8fd4536..b631c6f 100644 --- a/index.html +++ b/index.html @@ -17,8 +17,8 @@ - - + + @@ -60,48 +60,83 @@ -

hmstimer is an R package to track elapsed clock time using a hms::hms scalar, which if running has an attribute named start that specifies the system time when the timer was started.

-

The elapsed time is the value of the scalar plus the difference between the current system time and the system time when the timer was started.

+

hmstimer is an R package to track elapsed clock time using a hms::hms scalar.

+

hmstimer was originally developed to time Bayesian model runs. It should not be used to estimate how long extremely fast code takes to execute as the package code adds a small time cost.

+

Create and start a timer with tmr_timer(start = TRUE).

 library(hmstimer)
 
-tmr <- tmr_timer(seconds = 125, start = TRUE)
-tmr
-#> 00:02:05
-tmr_elapsed(tmr)
-#> 00:02:05.002463
-tmr
-#> 00:02:05
-tmr_elapsed(tmr)
-#> 00:02:05.00374
-
-tmr <- tmr_stop(tmr)
+tmr <- tmr_timer(start = TRUE)
+Sys.sleep(0.1)
+str(tmr)
+#>  'hms' num 00:00:00
+#>  - attr(*, "units")= chr "secs"
+#>  - attr(*, "title")= chr ""
+#>  - attr(*, "start")= num 1.72e+09
+hms::as_hms(tmr)
+#> 00:00:00
+

Get the elapsed time with tmr_elapsed(). The title is optional.

+
+tmr <- tmr_timer(start = TRUE, title = "my timer")
 
-tmr
-#> 00:02:05.004366
+Sys.sleep(0.1)
 tmr_elapsed(tmr)
-#> 00:02:05.004366
+#> 00:00:00.103417
 
-tmr_format(tmr, digits = 4)
-#> [1] "00:02:05.0044"
+Sys.sleep(0.1)
+tmr_elapsed(tmr)
+#> 00:00:00.212112
+

Stop the timer with tmr_stop().

+
+tmr <- tmr_stop(tmr)
+tmr_elapsed(tmr)
+#> 00:00:00.216109
 
-with_timer({
-  Sys.sleep(1)
-  1
+Sys.sleep(1)
+tmr_elapsed(tmr)
+#> 00:00:00.216109
+

Restart the timer with tmr_start().

+
+tmr <- tmr_start(tmr)
+tmr_elapsed(tmr)
+#> 00:00:00.21697
+Sys.sleep(0.1)
+tmr_elapsed(tmr)
+#> 00:00:00.324928
+

There are several options for printing and formatting including coercing to a hms object.

+
+tmr <- tmr_stop(tmr)
+print(tmr)
+#> 00:00:00.333247
+tmr_print(tmr)
+#> [1] "00:00:00.333247 [my timer]"
+tmr_format(tmr, digits = 5)
+#> [1] "00:00:00.33325 [my timer]"
+

If running tmr_print() behaves differently.

+
+tmr <- tmr_start(tmr)
+tmr_print(tmr)
+#> [1] "14:44:58 (+00:00:01 => 14:44:59) [my timer]"
+

The time for a block of code to complete can be printed using with_timer().

+
+with_timer({
+  Sys.sleep(0.1)
+  Sys.sleep(0.1)
+  1 + 1
 })
-#> 00:00:01.005
-#> [1] 1
+#> 00:00:00.207 +#> [1] 2

Installation

To install the latest release version from CRAN.

-
+
 install.packages("hmstimer")

To install the latest development version from r-universe.

-
+
 install.packages("hmstimer", repos = c("https://poissonconsulting.r-universe.dev", "https://cloud.r-project.org"))

To install the latest development version from GitHub

-
+
 # install.packages("pak", repos = sprintf("https://r-lib.github.io/p/pak/stable/%s/%s/%s", .Platform$pkgType, R.Version()$os, R.Version()$arch))
 pak::pak("poissonconsulting/hmstimer")
diff --git a/pkgdown.yml b/pkgdown.yml index 1e3d760..a1ae8c2 100644 --- a/pkgdown.yml +++ b/pkgdown.yml @@ -2,7 +2,7 @@ pandoc: 3.1.11 pkgdown: 2.1.0 pkgdown_sha: ~ articles: {} -last_built: 2024-08-07T18:10Z +last_built: 2024-08-08T18:19Z urls: reference: https://poissonconsulting.github.io/hmstimer/reference article: https://poissonconsulting.github.io/hmstimer/articles diff --git a/reference/args.html b/reference/args.html new file mode 100644 index 0000000..ba78bbe --- /dev/null +++ b/reference/args.html @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/reference/arguments.html b/reference/arguments.html new file mode 100644 index 0000000..ba78bbe --- /dev/null +++ b/reference/arguments.html @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/reference/hms_timer.html b/reference/hms_timer.html index 165f55a..34e6c1c 100644 --- a/reference/hms_timer.html +++ b/reference/hms_timer.html @@ -54,9 +54,11 @@

Examples
str(tmr_timer())
 #>  'hms' num 00:00:00
 #>  - attr(*, "units")= chr "secs"
+#>  - attr(*, "title")= chr ""
 str(tmr_timer(1.5, start = TRUE))
 #>  'hms' num 00:00:01.5
 #>  - attr(*, "units")= chr "secs"
+#>  - attr(*, "title")= chr ""
 #>  - attr(*, "start")= num 1.72e+09
 
 x <- tmr_timer(1, start = TRUE)
@@ -66,7 +68,7 @@ 

Examplesprint(x) #> 00:00:01 print(tmr_elapsed(x)) -#> 00:00:01.104649 +#> 00:00:01.1043 print(x) #> 00:00:01

diff --git a/reference/hmstimer-package.html b/reference/hmstimer-package.html index ea46c21..66e8112 100644 --- a/reference/hmstimer-package.html +++ b/reference/hmstimer-package.html @@ -1,7 +1,7 @@ hmstimer: 'hms' Based Timer — hmstimer-package • hmstimer +Tracks elapsed clock time using a `hms::hms()` scalar. It was was originally developed to time Bayesian model runs. It should not be used to estimate how long extremely fast code takes to execute as the package code adds a small time cost."> Skip to contents @@ -36,7 +36,7 @@

-

Tracks elapsed clock time using a `hms::hms()` scalar, which if running has an attribute named start that specifies the system time when the timer was started. The elapsed time is the value of the scalar plus the difference between the current system time and the system time when the timer was started.

+

Tracks elapsed clock time using a `hms::hms()` scalar. It was was originally developed to time Bayesian model runs. It should not be used to estimate how long extremely fast code takes to execute as the package code adds a small time cost.

diff --git a/reference/index.html b/reference/index.html index 4fa9ac7..f563a18 100644 --- a/reference/index.html +++ b/reference/index.html @@ -142,6 +142,35 @@

Evaluate Timer
Format hms Timer

+

Title

+ +

Functions to confirm, get and set title

+ + +
+ + + + +
+ + tmr_is_titled() + +
+
Is hms Timer Title
+
+ + tmr_title() + +
+
Get Title hms Timer
+
+ + `tmr_title<-`() + +
+
Set Title hms Timer
+

Miscellaneous Functions

Miscellaneous functions

diff --git a/reference/local_timer.html b/reference/local_timer.html index 3adf617..299c4f1 100644 --- a/reference/local_timer.html +++ b/reference/local_timer.html @@ -41,14 +41,26 @@

Usage

-
local_timer(.local_envir = rlang::caller_env())
+
local_timer(..., title = "", srcref = TRUE, .local_envir = rlang::caller_env())

Arguments

-
.local_envir
+
...
+

These dots are for future extensions and must be empty.

+ + +
title
+

A string of the title.

+ + +
srcref
+

A flag specifying whether to print the source reference.

+ + +
.local_envir

The environment to use for scoping.

@@ -65,7 +77,7 @@

Examples 10 } fun() -#> 00:00:00.101 +#> 00:00:00.100 [<text>:2] #> [1] 10

diff --git a/reference/parameters.html b/reference/parameters.html new file mode 100644 index 0000000..ba78bbe --- /dev/null +++ b/reference/parameters.html @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/reference/params.html b/reference/params.html index 14a6113..984a4f6 100644 --- a/reference/params.html +++ b/reference/params.html @@ -1,5 +1,7 @@ -Parameter Descriptions for hmstimer Functions — params • hmstimer +Parameter Descriptions — params • hmstimer Skip to contents @@ -27,13 +29,14 @@
-

Parameter Descriptions for hmstimer Functions

+

Default parameter descriptions which may be overridden in individual +functions.

@@ -41,32 +44,60 @@

Arguments

-
.local_envir
-

The environment to use for scoping.

+
...
+

These dots are for future extensions and must be empty.

code
-

Code to time.

+

A line or block of R code.

digits
-

A whole number of the number of decimal places.

+

A count of the number of decimal places.

+ + +
print_title
+

A flag specifying whether to print the title.

seconds

A non-negative numeric scalar of the initial number of seconds.

+
srcref
+

A flag specifying whether to print the source reference.

+ +
start
-

A flag indicating whether to start the timer.

+

A flag specifying whether to start the timer.

+ + +
title
+

A string of the title.

+ + +
value
+

A string of the title.

x

A hms_timer().

+ +
.local_envir
+

The environment to use for scoping.

+
+
+

Details

+

A flag is a non-missing logical scalar.

+

A string is a non-missing character scalar.

+

A count is a non-missing non-negative integer scalar or double +scalar with no fractional part.

+
-
+