ID EN
Miscellaneous

quit

R Base 3.6.2

The function quit or its alias q terminate the current R session.

Syntax

R
quit(save = "default", status = 0, runLast = TRUE)
   q(save = "default", status = 0, runLast = TRUE)

Arguments

Parameter Description
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?

Details

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 normal termination, .Last() is executed if the function .Last 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. There is a system analogue, .Last.sys(), which is run after .Last() if runLast is true. Exactly what happens at termination of an R session depends on the platform and GUI interface in use. A typical sequence is

Examples

Example
R
# NOT RUN {
## Unix-flavour example
.Last <- function() {
  graphics.off() # close devices before printing
  cat("Now sending PDF graphics to the printer:\n")
  system("lpr Rplots.pdf")
  cat("bye bye...\n")
}
quit("yes")
# }

See Also

.First for setting things on startup.