Skip to main content

1.13) Quitting R And Saving


When you’ve finished a session, type q() to quit. When asked if you want to save the current workspace, saying "Yes" will produce an R workspace file in the directory where you were working (hint: use getwd() first to check where that is!). This file will contain the objects that have been created and a record of the commands typed (accessible by using the up-arrow). By default the file will have a blank name, with only the extension ".Rdata" – and that’s fine (if you subsequently name it, e.g. within Windows Explorer, a new unnamed file will be produced the next time you quit in this way). So it’s best to have a separate directory for each workspace you want to maintain.

When asked if you want to save your script file, always say "Yes". Make up a name and then add the extension ".R" to it (this is necessary, at least in Windows, so you can easily find it when you go to “Open Script” next time you start R).

Now it's time for a quiz...