This function behaves as `on.exit()`, but is run on error, and supports mappers.

on_error(f)

Arguments

f

a function to call on error

Value

A local error handler.

Examples


y <- function(num) {
  on_error(~ write(Sys.time(), "error_log.txt", append = TRUE))
  log(num)
}