timer: A (rough) timer

View source: R/timer.R

timerR Documentation

A (rough) timer

Description

Useful mainly in a script file to time, then log, each step (or process) in the file.

Usage

timer(
  process,
  notes = NULL,
  file = NULL,
  name = NULL,
  log = NULL,
  time_df = NULL,
  write_log = grepl("end", process)
)

Arguments

process

Character. Name of the process being timed.

notes

Character. Any notes associated with the process.

file

Character. Name of the (script) file.

name

Character. Might be the same as process, or an element over which process is being run. e.g. name could be a species name where the same function is being run over many different species.

log

Character. Path to write the log file.

time_df

Object name or null for the initiation of a timer.

write_log

Write the log after this process. Default is only where process contains 'end'.

Details

Timer can be re-started by including 'start' in a process.

Value

A dataframe (time_df), possibly with an additional row for the current process. If write_log then log file is written.

Examples

time_df <- timer("start script", file = "file 01", name = "example", log = "example.log")
Sys.sleep(1)
time_df <- timer("process 01", time_df = time_df)
Sys.sleep(1)
time_df
time_df <- timer("end script", time_df = time_df) # log.log written
Sys.sleep(1)
time_df <- timer("start script", file = "file 02", time_df = time_df)
Sys.sleep(1)
time_df <- timer("process 01", time_df = time_df, write_log = TRUE) # log.log written
time_df <- timer("end script", time_df = time_df) # log.log written

# clean up
rm(time_df)
unlink("example.log")


Acanthiza/envFunc documentation built on Aug. 19, 2024, 4:50 a.m.