These functions register one or more functions to be called when the
current R session begins or ends. The functions are evaluated in a local
environment and without exception handlers, which means that if one
produces an error, then none of the succeeding functions will be called.
To list currently registered functions, use fcns <- on_session_enter()
or fcns <- on_session_exit().
To remove all registered functions, use on_session_enter(replace = TRUE)
or on_session_exit(replace = TRUE).
The on_session_enter() function works by recording all fcn:s in an
internal list which will be evaluated via a custom
.First() function created in the global
environment. Any other .First() function on the search path, including
a pre-existing .First() function in the global environment, is called
at the end after registered functions have been called.
The on_session_exit() function works by recording all fcn:s in an
internal list which will be evaluated via a custom function that is called
when the global environment is garbage collected, which happens at the very
end of the R shutdown process.
Contrary to a .Last() function, which is not be
called if quit(runLast = FALSE) is used, functions registered via
on_session_exit() are always processed.
Registered on_session_exit() functions are called after quit() saves
any workspace image to file (./.RData), and after any .Last() has
been called.