| quit | R Documentation |
The functionquit or its aliasq terminate the currentR session.
quit(save = "default", status = 0, runLast = TRUE) q(save = "default", status = 0, runLast = TRUE)
save | a character string indicating whether the environment(workspace) should be saved, one of |
status | the (numerical) error status to be returned to theoperating system, where relevant. Conventionally |
runLast | should |
save must be one of"no","yes","ask" or"default". In the first case the workspaceis not saved, in the second it is saved and in the third the user isprompted and can also decidenot to quit. The default is toask in interactive use but may be overridden by command-linearguments (which must be supplied in non-interactive use).
Immediatelybefore normal termination,.Last() isexecuted if the function.Last exists andrunLast istrue. If in interactive use there are errors in the.Lastfunction, control will be returned to the command prompt, so do testthe function thoroughly. There is a system analogue,.Last.sys(), which is run after.Last() ifrunLast is true.
Exactly what happens at termination of anR session depends on theplatform and GUI interface in use. A typical sequence is to run.Last() and.Last.sys() (unlessrunLast isfalse), to save the workspace if requested (and in most cases alsoto save the session history: seesavehistory), thenrun any finalizers (seereg.finalizer) that have beenset to be run on exit, close all open graphics devices, remove thesession temporary directory and print any remaining warnings(e.g., from.Last() and device closure).
Some error status values are used byR itself. The default errorhandler for non-interactive use effectively callsq("no", 1, FALSE) and returns error status 1. Error status 2 is used forR‘suicide’, that is a catastrophic failure, and other smallnumbers are used by specific ports for initialization failures. Itis recommended that users choose statuses of 10 or more.
Valid values ofstatus are system-dependent, but0:255are normally valid. (Many OSes will report the last byte of thevalue, that is report the value modulo 256. But not all.)
The value of.Last is for the end user to control: asit can be replaced later in the session, it cannot safely be usedprogrammatically, e.g. by a package. The other way to set code to be runat the end of the session is to use afinalizer: seereg.finalizer.
TheR.app GUI on macOS has its own version of these functionswith slightly different behaviour for thesave argument (theGUI's ‘Startup’ preferences for this action are taken into account).
Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988)The New S Language.Wadsworth & Brooks/Cole.
.First for setting things on startup.
## 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")## End(Not run)Add the following code to your website.
For more information on customizing the embed code, readEmbedding Snippets.