The on.exit()
function is handy for variable clean up if global variables must be assigned.
Some parameters, especially those for graphics, can only be set globally. This small function is common when creating more specialized plots.
new_plot <- function(...) {
old_pars <- par(mar = c(5,4,4,2) + .1, mfrow = c(1,1))
on.exit(par(old_pars))
plot(...)
}