on.exit() Limitations
You should always call it with
add = TRUEto ensure that the call is added to the list of deferred tasks (instead of replaces).You should always call it with
after = FALSEto ensure that the cleanup occurs in reverse order to setup.It doesn’t work in the global environment for interactive checking.
You can’t wrap up
on.exit()in a helper function.