Part 10: Exiting R and Rcmdr

What’s on this page?

  1. Ready to quit an R session?
  2. Prompts during exit from R and R Commander
  3. To do on your own
  4. Quiz

What to do

  • Exit from R and R Commander
  • Make decisions about which files, if any, to save after an R session

How to do it

This page assumes you are working with R Commander.

1. Ready to quit an R session?

This is just a quick note about how to exit R and R Commander, and about which files, if any, to save upon exit.

To quit R, you can follow menu options in the RGUI

File → Exit

or type and submit

q()

To quit R Commander,

File → Exit

then select from options (Fig. 1)

  • From Commander
  • From Commander and R
  • Restart the Commander

Rcmdr menu: Quit R Commander

Figure 1. R Commander exit options

The options are straightforward, but you should try each and note whether or not the behavior of the command matches your expectations.

Note: To restart Commander, type and submit

Commander()

2. Prompts during exit from R and R Commander

By now you’ve started and exited R and R Commander several times.

Upon exiting R Commander, you are prompted with the choice to

  • Save script file?
  • Save R Markdown file?
  • Save output file?

These are pretty straightforward. Script files contain your commands. As you progress with data analysis you’ll build up approaches to analysis which involve use of many commands, functions, and manipulations of the data. In order to recreate the analysis, clearly, a saved record would be useful, even as you are just getting started out. Initially, you’re probably making mistakes with code, so really, no reason to save this.

If you have not generated a Markdown report, then you are given the opportunity to do so by saving the RMarkdown file. Again, initially, there’s little reason to do so. Use Markdown when you are ready to make a report of your work (recall). And lastly, the option to save an output file refers to saving all responses to the R commands you supplied during the session.

Upon exiting R you are prompted to

  • Save workspace image?

The workspace refers to the R environment and all objects created during an R session. For example, if you loaded an Excel worksheet and saved as object myData, then this will be stored in a file called .Rhistory.

Note the period at the start of Rhistory. This is a hold over from UNIX days, it signals the file will be hidden from the viewer (unless the user has made such files visible!). macOS obeys this convention. To make “hidden” files visible, open Finder and point to the folder. Press in sequence Cmd + Shift + . (period) and hidden files will be made visible (press keyboard sequence again to hide the files). Win10 ignores this convention and .Rhistory and other files beginning with a period are visible by default.

Thus, if workspace was saved, at next R session, the workspace is loaded from .Rhistory and, in this example, myData should be available.

Note: to see objects created during a session, type and submit

ls()

3. To do on your own

1. Assuming you’ve been working step by step from Part 1 to the current one, Part 10, you’ll have quite a bit of code and output in your R session. Use the

ls()

command to identify all objects you have created.

2. I recommend you should try saving then reloading upon restart of R and R Commander

  • script file
  • workspace image

and note whether or not the behavior of the command matches your expectations.

4. Page quiz


Exit R

Three questions from this page