This function records the expression given as its argument as needing to be executed when the current function exits (either naturally or as the result of an error). This is useful for resetting graphical parameters or performing other cleanup actions.
For instance, if plotting parameters are automatically adjusted in a function, use on.exit to adjust plotting parameters back to their original settings.
scatterBox <- function(x, y, ...){
opar <- par("mfrow", "mar")
on.exit(par(opar))
# ...
}