quit Function in R (2 Examples)


In this R tutorial you’ll learn how to terminate an R session using the quit function.

The article contains this content:

Let’s get started!


Example 1: Terminate an R Session Using quit() Function

In Example 1, I’ll illustrate how to close an R or RStudio session using the quit function.

We may simply use the default specifications of the quit function as shown below:

quit()              # Basic application of quit function

After executing the previous R code, the following output is returned to the RStudio console:


quit function in r


Next, we have to specify whether we want to save the current environment by typing y (i.e. yes) or n (i.e. no) to the RStudio console.

Specify your preference and hit enter to close your current RStudio session.


Example 2: Don’t Save Workspace When Using quit() Function

In this example, I’ll illustrate how to skip the step where you have to specify whether you want to save the current workspace.

For this, we can use the save argument within the quit function as shown below:

quit(save = "no")   # Specify save argument

After running the previous R code, the current R session is closed.


Video, Further Resources & Summary

Would you like to know more about the application of the quit function? Then you could have a look at the following video on my YouTube channel. I’m explaining the content of this tutorial in the video:


The YouTube video will be added soon.


Furthermore, you might read the related tutorials on Statistics Globe. A selection of other tutorials is shown below.


In this R post you have learned how to automatically close and exit an R session using the quit command. If you have additional questions, please let me know in the comments section.


Subscribe to the Statistics Globe Newsletter

Get regular updates on the latest tutorials, offers & news at Statistics Globe.
I hate spam & you may opt out anytime: Privacy Policy.

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.