quit package:base R Documentation _T_e_r_m_i_n_a_t_e _a_n _R _S_e_s_s_i_o_n _D_e_s_c_r_i_p_t_i_o_n: The function 'quit' or its alias 'q' terminate the current R session. _U_s_a_g_e: quit(save = "default", status = 0, runLast = TRUE) q(save = "default", status = 0, runLast = TRUE) .Last <- function(x) { ...... } _A_r_g_u_m_e_n_t_s: save: a character string indicating whether the environment (workspace) should be saved, one of '"no"', '"yes"', '"ask"' or '"default"'. status: the (numerical) error status to be returned to the operating system, where relevant. Conventionally '0' indicates successful completion. runLast: should '.Last()' be executed? _D_e_t_a_i_l_s: 'save' must be one of '"no"', '"yes"', '"ask"' or '"default"'. In the first case the workspace is not saved, in the second it is saved and in the third the user is prompted and can also decide _not_ to quit. The default is to ask in interactive use but may be overridden by command-line arguments (which must be supplied in non-interactive use). Immediately _before_ terminating, the function '.Last()' is executed if it exists and 'runLast' is true. If in interactive use there are errors in the '.Last' function, control will be returned to the command prompt, so do test the function thoroughly. Some error statuses are used by R itself. The default error handler for non-interactive effectively calls 'q("no", 1, FALSE)' and returns error code 1. Error status 2 is used for R 'suicide', that is a catastrophic failure, and other small numbers are used by specific ports for initialization failures. It is recommended that users choose statuses of 10 or more. Valid values of 'status' are system-dependent, but '0:255' are normally valid. _R_e_f_e_r_e_n_c_e_s: Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988) _The New S Language_. Wadsworth & Brooks/Cole. _S_e_e _A_l_s_o: '.First' for setting things on startup. _E_x_a_m_p_l_e_s: ## Not run: ## Unix-flavour example .Last <- function() { cat("Now sending PostScript graphics to the printer:\n") system("lpr Rplots.ps") cat("bye bye...\n") } quit("yes") ## End(Not run)