Closed krlmlr closed 1 month ago
Very interesting - do you want to spend sometime on this together when we are working this fall or do you want us to take a stab before?
Either way works for me. For reference, here's my own local_timer()
that also shows the caller's location.
local_timer <- function(title = NULL, frame = rlang::caller_env()) {
caller <- sys.call()
srcref <- utils::getSrcref(caller)
file <- utils::getSrcFilename(caller)
file_line <- paste0(file, ":", srcref[[1]])
if (is.null(title)) {
title <- file_line
} else {
title <- paste0(file_line, ": ", title)
}
tmr <- hmstimer::tmr_timer(start = TRUE)
message(title)
withr::defer(message(title, ": ", format(hmstimer::tmr_elapsed(tmr))), frame)
tmr
}
New function that wraps
tmr_timer(start = TRUE)
and shows the elapsed time when started and on exit (viawithr::defer()
). Useful for adding trace messages for debugging, in combination with #11.