Scripts and dataframes left opened in the previous session are not restored when restarting RStudio (second post)


In the latest version of RStudio, working in Windows 10, the Scripts and dataframes left open in the previous session are not restored when restarting RStudio, in spite of having checked the option "Restore previously open source documents at startup" in the Global Options menu. Any ideas of why is this happening? How can I solve it?

I posted this problem a couple of weeks ago but I haven't received any answer



1 Like


In the latest version of RStudio, working in Windows 10, the Scripts and dataframes left opened in the previous session are not restored when restarting RStudio, in spite of having checked the option "Restore previously open source documents at startup" in the Global Options menu. Any ideas of why is this happening? How can I solve it?



To help understand what's going on, here's RStudio's docs on using Projects.

When you are within a project and choose to either Quit, close the project, or open another project the following actions are taken:

  • .RData and/or .Rhistory are written to the project directory (if current options indicate they should be)
  • The list of open source documents is saved (so it can be restored next time the project is opened)
  • Other RStudio settings (as described above) are saved.
  • The R session is terminated.

I suspect there is something going on that is preventing this action from being taken. For example, if I clear all objects from my global environment, and then open .RData, the global environment takes me back to my last project save.

There could be a bunch of ways that could happen. For example not having full write access, and programs that prevent you from updating that file.

Some system Information could be useful as well

System Information:

  • RStudio Edition: (Desktop or Server)
  • RStudio Version:
  • OS Version:
  • R Version:

Thank you very much for your kind response. I have been using RStudio for quite a long time, and I never had this problem.
When not in a project, the workspace, history and the files left opened when closing are restored after launching RStudio again, but if I am in a project, just the workspace and the history are restored. Other issue: I prefer to work with the grid view of the global environment, but now RStudio always starts with the list view.
It is not a big deal to look for the files I left opened, I just want to know if other people have the same problem or it is something in the configuration of my computer that I can fix with the help of an expert.
Here is the information:
RStudio Edition: Desktop
The version of RStudio is RStudio 2021.09.0+351 "Ghost Orchid" Release (077589bcad3467ae79f318afe8641a1899a51606, 2021-09-20) for Windows
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) QtWebEngine/5.12.8 Chrome/69.0.3497.128 Safari/537.36

The OS is Windows 10 Home Single Language, version 20H2
The R version is R version 4.0.2 (2020-06-22) -- "Taking Off Again"

Thanks in advance

Sorry for this. I personally love how my RStudio projects reopen my files to exactly where I left off, even weeks later.

I see you are on the most recent release, and I don't see any issues related to this. If you'd be up for it, I think the IDE team would appreciate a bug report to help understand and diagnose the issue.

And then I'd encourage you to upgrade your RStudio IDE once we put out a new minor release, (basically, check the download RStudio page in a week).

Thank you, your comments were very helpful. I started working with python in RStudio and I ran into some problems than lent me to change some configuration variables. Surely I changed something that now is kept in the registry.
I will upgrade my RStudio as soon as possible.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.

Continuing the discussion from Scripts and dataframes left opened in the previous session are not restored when restarting RStudio (second post):

Hi Everyone,

Previously, I posted about a problem I was having where RStudio was not restoring my open documents upon reopening an RStudio Project. I found a number of posts here on the forums where other people had this issue, but there seemed to be no reproducible reason for the problem. In my case, I discovered both the cause of the problem and a solution for it.

Summary of the Problem

For some of my RStudio projects, upon loading a previously saved RStudio project, RStudio was not restoring to the Source pane the documents I had open when the project was last saved.

Cause of the Problem

I determined that the cause of the problem was file lock contention between RStudio and the Google Drive Backup Application (GDBA), which was causing some files in the .Rproj.user subdirectory to become corrupted. Once corrupted, RStudio would not restore the document layout to the Source pane when the project was reloaded.

How can corrupted projects be fixed?

  1. Close the GDBA.

  2. Close RStudio.

  3. Delete the affected .Rproj.user subdirectory.

  4. Reopen RStudio and load the project.

How can the problem be prevented?

  1. Option 1: Stop using the Google Drive Backup application.

  2. Option 2: Be sure that the Google Drive Backup application is not running when RStudio is running.

  3. Option 3: Do not work on RStudio projects that have been saved to a directory that is monitored by the Google Drive Backup Application.

Detailed Explanation of Problem and Solution

On my Windows 11 computer, I run the Google Drive application, which automatically synchronizes a specified storage location on my local hard drive, as well as all of its subdirectories.

If I open an RStudio project that is located in one of the subdirectories monitored by the Google Drive Backup application (GDBA), the GDBA will notice the file changes made by the RStudio IDE in the corresponding project's .Rproj.user subdirectory and attempt to start backing up all of the changed files.

I'm guessing that RStudio has a lock on these files, as the GDBA will keep attempting to acquire its own lock on them. Despite being unable to do so, the GDBA will keep trying furiously to get a lock on these files. My assumption is that this file lock contention results in corruption of some files in the .Rproj.user subdirectory, which is the source of the underlying problem that is the subject of this post.

Unfortunately for users of both RStudio and the GDBA on Windows, neither of these apps actively alert the user when this problem occurs. If a user opens the GDBA and reviews the error log, it will show the files that it is having trouble backing up. However, as soon as the user exits RStudio, the GDBA will successfully complete its backup of these files, and the error logs will not show any problem.

Worse still, upon opening a saved project, the corrupted files in the .Rproj.user subdirectory will prevent RStudio from restoring the documents in the source pane, but the user will not receive any error notification.

To fix a project where the .Rproj.user subdirectory has become corrupted, I use the following procedure.

  1. If the affected project is located in a directory location monitored by the Google Drive Backup application, be sure to disable the GDBA.

  2. Close RStudio.

  3. Delete the .Rproj.user subdirectory within the affected project.

  4. Reopen RStudio.

  5. Load the affected RStudio project.

Now, the IDE will behave properly and restore the source pane layout configuration when a project is reloaded. If you use this procedure, please note that RStudio will not recovery the layout configuration before the files in the .Rproj.user subdirectory became corrupted. However, it will work correctly from that point forward.

All of this headache could be avoided if Google would give users of its Google Drive Backup application an option to specify file or folder patters to ignore. As a web search will show, this feature request has been made countless times over the years, and Google has made clear that they aren't going to implement it.

Thus, I have started closing the Google Drive Backup app before I start RStudio. Also, I've stopped creating RStudio projects in folders monitored by the Google Drive Backup application. Instead, I have a Github repo that I use to back up all of my personal RStudio projects. Although I wish I could save my RStudio projects to my Google Drive, this file lock contention conflict has forced me to stop using RStudio to work on projects that are saved to a location monitored by the GDBA.

Truth be told, compared to Google Drive, Github is a better place to store software projects anyway, which includes RStudio projects. Also, because RStudio has direct support git built in to it, the burden for using this approach is lessened. With this approach, now, all of my small RStudio projects are handled with the same level of care and robustness as my professional software projects.