| 1 |
% Generated by roxygen2: do not edit by hand |
| 2 |
% Please edit documentation in R/utils.R |
| 3 |
\name{exit_call} |
| 4 |
\alias{exit_call} |
| 5 |
\title{Call \code{on.exit()} in a parent function} |
| 6 |
\usage{ |
| 7 |
exit_call(fun, n = 2, ...) |
| 8 |
} |
| 9 |
\arguments{ |
| 10 |
\item{fun}{A function to be called when the parent function exits.} |
| 11 |
|
| 12 |
\item{n}{The parent frame number. For \code{n = 1}, \code{exit_call(fun)} is |
| 13 |
the same as \code{on.exit(fun())}; \code{n = 2} means adding |
| 14 |
\code{on.exit(fun())} in the parent function; \code{n = 3} means the |
| 15 |
grandparent, etc.} |
| 16 |
|
| 17 |
\item{...}{Other arguments to be passed to \code{on.exit()}.} |
| 18 |
} |
| 19 |
\description{ |
| 20 |
The function \code{\link[=on.exit]{on.exit()}} is often used to perform tasks when the |
| 21 |
current function exits. This \code{exit_call()} function allows calling a |
| 22 |
function when a parent function exits (thinking of it as inserting an |
| 23 |
\code{on.exit()} call into the parent function). |
| 24 |
} |
| 25 |
\examples{ |
| 26 |
f = function(x) { |
| 27 |
print(x) |
| 28 |
xfun::exit_call(function() print("The parent function is exiting!")) |
| 29 |
} |
| 30 |
g = function(y) { |
| 31 |
f(y) |
| 32 |
print("f() has been called!") |
| 33 |
} |
| 34 |
g("An argument of g()!") |
| 35 |
} |
| 36 |
\references{ |
| 37 |
This function was inspired by Kevin Ushey: |
| 38 |
\url{https://yihui.org/en/2017/12/on-exit-parent/} |
| 39 |
} |