Search notes:

R function: on.exit

on.exit records a function to be called when the current function exits.
Note that the function is not evaluated when on.exit() is called.
f_two <- function() {
  on.exit(print('f_two exited'));

  print('I am in f_two');
}

f_one <- function() {
  on.exit(print('f_one exited'));

  print('I am in f_one and am going to call f_two');
  f_two();
}

f_one();
#
#  I am in f_one and am going to call f_two
#  I am in f_two
#  f_two exited
#  f_one exited
Github repository about-r, path: /functions/on.exit.R

See also

Index to (some) R functions

Index

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/developm...', 1758200825, '216.73.216.150', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/development/languages/R/functions/on_exit(62): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78