addLast                package:gtools                R Documentation

_A_d_d _a _f_u_n_c_t_i_o_n _t_o _b_e _e_x_e_c_u_t_e_d _w_h_e_n _R _e_x_i_t_s.

_D_e_s_c_r_i_p_t_i_o_n:

     Add a function to be executed when R exits.

_U_s_a_g_e:

     addLast(fun)

_A_r_g_u_m_e_n_t_s:

     fun: Function to be called.

_D_e_t_a_i_l_s:

     'addLast' defines '.Last' (if not already present) or redifines it
     so that the function 'fun' will be called when R exits.  The
     latter is accomplished by saving the current definition of '.Last'
     and creating a new '.Last' function that calls 'fun' and then the
     original '.Last' function.

_V_a_l_u_e:

     None.

_A_u_t_h_o_r(_s):

     Gregory R. Warnes gregory.r.warnes@pfizer.com

_S_e_e _A_l_s_o:

     '.Last'

_E_x_a_m_p_l_e_s:

     ## Not run: 
     ## Print a couple of cute messages when R exits.
     helloWorld <- function() cat("\nHello World!\n")
     byeWorld <- function() cat("\nGoodbye World!\n")

     addLast(byeWorld)
     addLast(helloWorld)

     q("no")

     ## Should yield:
     ##
     ##   Save workspace image? [y/n/c]: n
     ##
     ##   Hello World!
     ##
     ##   Goodbye World!
     ##
     ##   Process R finished at Tue Nov 22 10:28:55 2005

     ## Unix-flavour example: send Rplots.ps to printer on exit.
     myLast <- function()
     {
       cat("Now sending PostScript graphics to the printer:\n")
       system("lpr Rplots.ps")
       cat("bye bye...\n")
     }
     addLast(myLast)
     quit("yes")

     ## Should yield:
     ##
     ##  Now sending PostScript graphics to the printer:
     ##  lpr: job 1341 queued
     ##  bye bye...
     ##
     ##   Process R finished at Tue Nov 22 10:28:55 2005
     ## End(Not run)

