1.6 Restart R regularly

Have you tried turning it off and on again? It is vital to restart R regularly. Restarting R helps to avoid accidentally using the wrong data or functions stored in the environment. Restarting R only takes a second and we do it several times per day! Once you get used to saving everything in a script, you’ll always be happy to restart R. This will help you develop robust and reproducible data analysis skills.

You can restart R by clicking on Session -> Restart R (top menu).

Configuring your RStudio Tools -> Global Options:  Untick ``Restore .RData into Workspace on Exit" and Set ``Save .RData on exit" to Never.

FIGURE 1.3: Configuring your RStudio Tools -> Global Options: Untick Restore .RData into Workspace on Exit" and SetSave .RData on exit" to Never.

Furthermore, RStudio has a default setting that is no longer considered best practice (Figure 1.3). After installing RStudio, you should go change two small but important things in Tools -> Global Options:

  1. Uncheck “Restore .RData into Workspace on startup”
  2. Set “Save .RData on exit” to Never

This does not mean you can’t or shouldn’t save your work in .RData/.rda files. But it is best to do it consciously and load exactly what you want to load. Letting R silently save and load everything for you may also include broken data or objects.