The function on.exit()
is often used to perform tasks when the
current function exits. This exit_call()
function allows calling a
function when a parent function exits (thinking of it as inserting an
on.exit()
call into the parent function).
exit_call(fun, n = 2, ...)
A function to be called when the parent function exits.
The parent frame number. For n = 1
, exit_call(fun)
is
the same as on.exit(fun())
; n = 2
means adding
on.exit(fun())
in the parent function; n = 3
means the
grandparent, etc.
Other arguments to be passed to on.exit()
.
This function was inspired by Kevin Ushey: https://yihui.org/en/2017/12/on-exit-parent/