You might have noticed that the startup speed of RStudio varies. But how can you fix RStudio when its loading time is really, really long? In this blog post I elaborate on the problem and how you can solve it.
Everytime you close RStudio while working on your projects, RStudio will ask if you want to save the workspace image to an .RData file. The workspace contains quite a lot of elements:
- your options — like scientific notation preferences
- your history — the commands you used in the terminal
- your data, values and functions — data frames, vectors, …
However, if you decide to save your workspace to an .RData file, you could run into startup problems later. If you’re working with a lot of data, and you have data frames of multiple gigabytes, starting RStudio can take minutes.
Here’s what you can do to prevent it.
- Go to Tools > Global Options… in the menu
- Uncheck “Restore .RData into workspace at startup”
- Besides starting up, If you want to speed up shutting down RStudio too, set “Save workspace to .RData on exit” to Never.
A couple of years ago I couldn’t even open R, because it was trying to open my last project, and it had a huge .RData file. So there’s no way you can change the setting in the RStudio Global Options menu. However, there are a couple of things you can do to start RStudio and change the setting.
- Remove the .RData file through File Explorer.
- Start a project (an .RProj file) without a large .RData file
- Change the setting through the RStudio configuration file — instructions below
The RStudio configuration file can be found in:
Translating this to Windows:
The setting you should change is LoadRData. You should set it to “0”.
By the way, if you’re having trouble understanding some of the code and concepts, I can highly recommend “An Introduction to Statistical Learning: with Applications in R”, which is the must-have data science bible. If you simply need an introduction into R, and less into the Data Science part, I can absolutely recommend this book by Richard Cotton. Hope it helps!