restore unsaved RStudio script

How to restore closed unsaved script in RStudio

If you just recently closed the unsaved (untitled) source tab in RStudio, there is a good chance that you can get it back. Try to restore unsaved RStudio script in 3 different ways.

1. If you are a Windows user, take a look at this folder that contains the folder that starts with “s-“. RStudio should be open.


There are usually files that end with “-contents”. Open some of them in a text editor and restore unsaved source code.

2. Take a look at the history_database file.

If you are a Windows user, the location of that file is here. It might be useful if previously described files are not available.

3. Take a look at the History tab.

Contents of the history tab are located in the Rhistory file. You can locate by using function getwd.


If you want to get the current RStudio script path, then here is how to do that.





3 responses to “How to restore closed unsaved script in RStudio”

  1. Matthias

    Thank you so much for this hint!!!

  2. Dzmitry Rybalka

    Thank you, sir! You made my day

  3. Larry

    Thank you for this, literally saved me re-doing 5 hours of work. 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *