Skip to contents

This function is meant to be called frequently throughout a main function, and if verbose performance monitoring is enabled then it will print the elapsed time since (a) initialisation via monitor_start() and (b) since the last step was recorded via this function.

Usage

monitor(monitor_performance, start_time, previous_time, message)

Arguments

monitor_performance

logical. Whether verbose performance monitoring should be enabled.

start_time

POSIXct. The time at which the overarching function was initialised (generally via monitor_start()).

previous_time

POSIXct. The time at which the previous step was recorded (via a prior call to monitor()).

message

character. The message to be printed, generally indicating what this step is doing

Value

POSIXct the time at which the function was called, via Sys.time().

Examples

## Initialise monitoring
start_time <- monitor_start(TRUE, "my_cool_function")
#>  Verbose monitoring enabled
#>  (2026-03-06 02:19:55) my_cool_function start

## Step 1
monitor_time <- monitor(TRUE, start_time, start_time, "performing step 1")
#>  (0.005 secs elapsed; 0.005 secs total) performing step 1
x <- 2 + 2

## Step 2
monitor_time <- monitor(TRUE, start_time, monitor_time, "performing step 2")
#>  (0.003 secs elapsed; 0.008 secs total) performing step 2
y <- 10.5^6 %% 345789

## Step 3
monitor_time <- monitor(TRUE, start_time, monitor_time, "performing step 3")
#>  (0.003 secs elapsed; 0.010 secs total) performing step 3
z <- y / x^2

## Conclude monitoring
monitor_time <- monitor(TRUE, start_time, monitor_time, "done")
#>  (0.003 secs elapsed; 0.013 secs total) done