Quit & Restart Clean R Session from within R (Example)
In this tutorial, I’ll illustrate how to close and restart a new R programming session from within RStudio in the R programming language.
The article will contain these content blocks:
Let’s dig in.
Example: Restart R Session Using .rs.restartR Function
The following R programming code explains how to quit and restart R in an automatized way by applying the .rs.restartR command. Have a look at the following R syntax:
.rs.restartR() # Restart R session
After running the previous line of code, something like the following should appear in your RStudio console:
# Restarting R session... # # Microsoft R Open 3.5.3 # The enhanced R distribution from Microsoft # Microsoft packages Copyright (C) 2019 Microsoft Corporation # # Using the Intel MKL for parallel mathematical computing (using 4 cores). # # Default CRAN mirror snapshot taken on 2019-04-15. # See: https://mran.microsoft.com/.
Note that your environment will keep all data objects and add-on packages are still attached at this point.
Video & Further Resources
Do you want to learn more about restarting R automatically? Then I can recommend to have a look at the following video that I have published on my YouTube channel. I’m showing the R programming code of this article in the video.
The YouTube video will be added soon.
In addition, you might read the other articles of Statistics Globe:
In this article, I explained how to reopen a clean R session automatically in the R programming language. In case you have additional questions, let me know in the comments. In addition, please subscribe to my email newsletter to receive updates on the newest articles.
Statistics Globe Newsletter