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 RStudio script in 2 different ways.
1. If you are a Windows user, take a look at this folder.
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 tab.