Package 'hmstimer'

Title: 'hms' Based Timer
Description: 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.
Authors: Joe Thorley [aut, cre] , Nadine Hussein [ctb] , Poisson Consulting [cph, fnd]
Maintainer: Joe Thorley <[email protected]>
License: MIT + file LICENSE
Version: 0.2.1
Built: 2024-06-20 04:30:20 UTC
Source: https://github.com/cran/hmstimer

Help Index


hms Timer

Description

A hms Timer is a hms::hms() scalar which if running has an attribute named start that specifies the system time when the timer was started.

Details

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.

Examples

str(tmr_timer())
str(tmr_timer(1.5, start = TRUE))

x <- tmr_timer(1, start = TRUE)
print(x)
Sys.sleep(0.1)
print(x)
print(tmr_elapsed(x))
print(x)

Ceiling hms Timer

Description

Rounds a hms_timer() up to the nearest second.

Usage

tmr_ceiling(x)

Arguments

x

A hms_timer().

Value

A hms_timer().

See Also

Other round: tmr_floor(), tmr_format(), tmr_round()

Examples

tmr_ceiling(tmr_timer(18.9))
tmr_ceiling(tmr_timer(122.1))

Elapsed Time hms Timer

Description

Returns the elapsed time for a hms_timer() as a hms_timer().

Usage

tmr_elapsed(x)

Arguments

x

A hms_timer().

Details

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.

If the original hms_timer() was running then the new hms_timer() is assigned an attribute named start of the current system time.

Value

A hms_timer() of the elapsed time.

See Also

Other start_stop: tmr_is_started(), tmr_is_stopped(), tmr_print(), tmr_reset(), tmr_start(), tmr_stop(), tmr_timer()

Examples

tmr <- tmr_start(tmr_timer())
print(tmr_elapsed(tmr))
Sys.sleep(0.01)
print(tmr_elapsed(tmr))
tmr <- tmr_stop(tmr)
print(tmr_elapsed(tmr))
Sys.sleep(0.01)
print(tmr_elapsed(tmr))

Floor hms Timer

Description

Rounds a hms_timer() down to the nearest second.

Usage

tmr_floor(x)

Arguments

x

A hms_timer().

Value

A hms_timer().

See Also

Other round: tmr_ceiling(), tmr_format(), tmr_round()

Examples

tmr_floor(tmr_timer(18.9))
tmr_floor(tmr_timer(122.1))

Format hms Timer

Description

Converts a hms_timer() to a string of the clock time after rounding it to the number of digits.

Usage

tmr_format(x, digits = 3)

Arguments

x

A hms_timer().

digits

A whole number of the number of decimal places.

Details

Negative values of digit are not permitted.

Value

A character string.

See Also

Other round: tmr_ceiling(), tmr_floor(), tmr_round()

Examples

tmr_format(tmr_timer(61.66))
tmr_format(tmr_timer(61.66), digits = 0)

Is hms Timer Started

Description

Tests if a hms_timer() is started (as indicated by the presence of an attribute named start).

Usage

tmr_is_started(x)

Arguments

x

A hms_timer().

Value

A flag (TRUE or FALSE).

See Also

Other start_stop: tmr_elapsed(), tmr_is_stopped(), tmr_print(), tmr_reset(), tmr_start(), tmr_stop(), tmr_timer()

Examples

tmr <- tmr_timer(start = TRUE)
print(tmr_is_started(tmr))
tmr <- tmr_stop(tmr)
print(tmr_is_started(tmr))

Is hms Timer Stopped

Description

Tests if a hms_timer() is stopped (as indicated by the absence of an attribute named start).

Usage

tmr_is_stopped(x)

Arguments

x

A hms_timer().

Value

A flag.

See Also

Other start_stop: tmr_elapsed(), tmr_is_started(), tmr_print(), tmr_reset(), tmr_start(), tmr_stop(), tmr_timer()

Examples

tmr <- tmr_timer(start = TRUE)
print(tmr_is_stopped(tmr))
tmr <- tmr_stop(tmr)
print(tmr_is_stopped(tmr))

Print hms Timer

Description

Returns the elapsed time for a hms_timer() from the system time when the timer was started and the current system time as an hms time.

Usage

tmr_print(x)

Arguments

x

A hms_timer().

Details

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.

Value

A character string.

See Also

Other start_stop: tmr_elapsed(), tmr_is_started(), tmr_is_stopped(), tmr_reset(), tmr_start(), tmr_stop(), tmr_timer()

Examples

x <- tmr_start(tmr_timer())
tmr_print(x)

Reset hms Timer

Description

Resets a hms_timer() by creating a new one.

Usage

tmr_reset(x, seconds = 0)

Arguments

x

A hms_timer().

seconds

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

Value

A hms_timer().

See Also

Other start_stop: tmr_elapsed(), tmr_is_started(), tmr_is_stopped(), tmr_print(), tmr_start(), tmr_stop(), tmr_timer()

Examples

tmr <- tmr_timer(10)
print(tmr)
tmr_reset(tmr)

Round hms Timer

Description

Rounds a hms_timer() after updating it to the elapsed time.

Usage

tmr_round(x, digits = 0)

Arguments

x

A hms_timer().

digits

A whole number of the number of decimal places.

Details

Negative values of digit are permitted.

Value

A hms_timer().

See Also

Other round: tmr_ceiling(), tmr_floor(), tmr_format()

Examples

tmr_round(tmr_timer(18.9))
tmr_round(tmr_timer(18.9), 1)
tmr_round(tmr_timer(18.9), -1)
tmr_round(tmr_timer(121), -2) # 121 is rounded to 100 seconds

Start hms Timer

Description

Starts a hms_timer() by adding an attribute named start of the current system time.

Usage

tmr_start(x)

Arguments

x

A hms_timer().

Details

If the hms_timer() is already started, the function simply issues a warning and returns the original object.

Value

A started hms_timer().

See Also

Other start_stop: tmr_elapsed(), tmr_is_started(), tmr_is_stopped(), tmr_print(), tmr_reset(), tmr_stop(), tmr_timer()

Examples

tmr <- tmr_start(tmr_timer())
print(tmr_elapsed(tmr))
Sys.sleep(0.01)
print(tmr_elapsed(tmr))

Stop hms Timer

Description

Stops a hms_timer() after updating it to the elapsed time.

Usage

tmr_stop(x)

Arguments

x

A hms_timer().

Details

If the hms_timer() is already stopped, the function simply issues a warning and returns the original object.

Value

A stopped hms_timer().

See Also

Other start_stop: tmr_elapsed(), tmr_is_started(), tmr_is_stopped(), tmr_print(), tmr_reset(), tmr_start(), tmr_timer()

Examples

tmr <- tmr_stop(tmr_timer(start = TRUE))
print(tmr_elapsed(tmr))
Sys.sleep(0.01)
print(tmr_elapsed(tmr))

Create hms Timer

Description

Creates a hms_timer().

Usage

tmr_timer(seconds = 0, start = FALSE)

Arguments

seconds

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

start

A flag indicating whether to start the timer.

Value

A hms_timer().

See Also

Other start_stop: tmr_elapsed(), tmr_is_started(), tmr_is_stopped(), tmr_print(), tmr_reset(), tmr_start(), tmr_stop()

Examples

tmr <- tmr_timer()
print(tmr)
class(tmr)