RStudio freezes on "saving workspace image," previously saved .RData file disappears - r

First, I've also posted this question on the RStudio Support page. If I get a response there, I will post it here for all to see (and vice versa).
I'm enjoying RStudio but am having trouble using Rprojects to save model outputs. I'm running sets of models that take ~1 day to run, so this is really setting me back. This is on an iMac running 10.9.5 (Mavericks).
Here's what happens:
I close the project and allow the "saving workspace image" to go through. (This is taking ~15 min, and the Rdata files are 6GB - this seems surprisingly large to me).
Often there is no problem upon reopening, the Rdata files are restored, and I see the objects I've created in the Global Environment pane. I run another model (or set of them), and close the project again. RStudio now gets hung up on "saving workspace image." Eventually, the wheel showing that this is active stops turning. Sometimes the mouse disappears from the screen and the entire computer freezes.
I either force RStudio to close, or force the computer to shutdown. When I restart and open RStudio, then load the Rproject, the Global Environment is empty. In the Files pane, there are no .RData files shown.
When I check the Rproject directory in Finder, there are multiple .RDataTmp (hidden) files. I'm not clear whether I can use any of them to recover my data, or how to attempt to load them in RStudio.
Solutions I've tried so far:
Updating everything, including R, RStudio, and Safari, per another post on RStudio Support.
Disabling my syncing program (SugarSync) from updating .Rproj.user file, also after reading a post there.
Enabling access for RStudio in the Privacy/Security settings.
I haven't been able to find any other possible solutions, and I am growing frustrated with testing this out, as it seems to happen only intermittently and (sigh) after the problem seems revolved, such that I've run a whole bunch of models and have a good deal of data to lose! This makes me wonder whether (a) the universe is simply cruel, or (b) it's the large file size that is causing the problem. The other option is (c) both.
I read elsewhere on RStudio Support that file compression can be enabled, but that this will slow the process of saving. Since it's already taking quite a long time to save upon closing the project and I'm not clear on why it might help, I'm hesitant to enable file compression until I know more.
Thanks for your help,
MK

Related

Rstudio potential memory leak / background activity?

I’m having a lot of trouble working with Rstudio on a new PC. I could not find a solution searching the web.
When Rstudio is on, it is constantly eating up memory until it becomes unworkable. If I work on an existing project, it takes half an hour to an hour to become impossible to work with. If I start a new project without loading any objects or packages, just writing scripts without even running them, it takes longer to reach that point, however, it still does.
When I first start the program, the Task Manager shows memory usage of 950-1000 MB already (sometimes larger), and as I work, it climbs up to 6000 MB at which point it is impossible to work with as every activity is delayed and 'stuck'. Just to compare, on my old PC while working on the program, the Task Manager shows 100-150 MB. When I click the "Memory Usage Report" within Rstudio, the "used by session" is very small, the "used by system" is almost at a maximum yet Rstudio is the only thing taking up they system memory on the PC.
Things I tried: installing older versions of both R and Rstudio, pausing my anti-virus program, changing compatibility mode, zoom on "100%". It feels like Rstudio is continuously running something in the background as the memory usage keeps growing (and quite quickly). But maybe it is something else entirely.
I am currently using the latest versions of R and Rstudio (4.1.2, and 2021.09.0-351), on a PC with processor Intel i7, x64 bit, RAM 16GM, Windows 10.
What should I look for at this point?
On Windows, there is several typical memory or CPU issues with Rstudio. In my answer, I explain how the Rstudio interface itself use memory and CPU, as soon as you open a project (e.g., when Rstudio show you some .Rmd files). The memory / CPU cost associated with the computation is not covered in my answer (i.e. when you have performance issues when executing a line of code = not covered).
When working on 'long' .Rmd files within Rstudio on Windows, the CPU and/or memory usage get sometimes very high and increases progressively (e.g., because of a process named 'Qtwebengineprocess'). To solve the problem caused by long Rmd files loaded within a Rstudio session, you should:
pay attention to the process of Rstudio that consume memory, when scanning your code (i.e. disable or enable stuff in the 'Global options' menu of Rstudio). For example, try to disable 'inline display'(Tools => Global options => Rmarkdown => Show equation and image preview => Never). This post put me on this way to consider that memory / CPU leak are sometimes due to Rstudio itself, nor the data or the code.
set up a bookdown project, in order to split your large Rmd files into several Rmd. See here.
Bonus step, see if there is a conflict in some packages which are loaded with the command tidyverse_conflicts(), but it's already a 'computing problem' (not covered here).

R studio not responding

My RStudio is opening multiple processes(opening R Studio in different windows) when I open just one. I am not able to open any project. It becomes unresponsive. I tried using in compatibility mode, running as admin and also uninstalled. But still,(here's the image) the same problem persists. Can someone please help me?
Before you reinstall everything, which may take a lot of time, it is worth removing application data, which is a cache R keeps of last sessions etc. It involves settings such as information from last session, etc which RStudio tries to reopen every time you open it.
For app data, look under your user folder which must be somewhere like
c:\Users\<your_user_here\AppData\Local
c:\Users\<your_user_here\AppData\Local\LocalLow
c:\Users\<your_user_here\AppData\Roaming
Delete every subfolder called R, RStudio-Desktop or RStudio under these folders. Don't worry, you won't lose your source program files and projects. It may help you recover everything without having to start over from scratch.

Rstudio is painfully slow

Suddenly, Rstudio is painfully slow, and now it is unusable. This means, I open it up and there is a lag of several seconds if I type anything. I have explored all the options I can come up with:
1. re-installing both R and Rstudio (although I am not 100% sure I could remove all components),
2. trying to reset settings.... the obvious things such as clearing the workspace and the console.
The size of my data is negligible. I cannot think of anything else.... any ideas?
The only observation i can make that shows something could be wrong with the configuration is (sometimes), I see "gctorture false" as a value in the environment.
Just a guess, but ?gctorture says
Provokes garbage collection on (nearly) every memory allocation.
Intended to ferret out memory protection bugs. Also makes R run
_very_ slowly, unfortunately.
which sounds about right for your problem! You could try
gctorture(FALSE)
If that speeds things up, then look for somewhere that this might have been set, e.g., in a .Rprofile (current working directory, or your user home directory, or the installation directory of R; see ?.Rprofile) and make sure that you start R without loading any .Rhistory or .RData files (again in the working directory, your home directory, etc.)
I had a RStudio project with Git Version Control and then it became very slow. I solved the problem by removing the Git Version Control

How to recover RStudio session after crash?

I would like to know how to restore my previous RStudio session after RStudio and the R session crashed.
Background:
I find that my R session crashes very often, at random times for random reasons. I am fine with that I guess.
Most of the time RStudio restarts the R session and I can continue.
But sometimes it just freezes at which time I noticed power cycling the entire machine allows RStudio to recover and even reload my old session.
Stupid me, I don't think power cycling is a good idea so I manually killed the R session, but then RStudio responded but was not really working so I restarted it and it came back with an empty work-space.
I have been backing up with Session->Save Workspace As, but it seems to do nothing as recovering leaves me with the blank empty environment.
I am looking to restore the RStudio display, including the command history , which for a novice like me is precious, and my list of open scripts, some of which were unsaved at the time of the crash.
I am assuming since RStudio can recover itself, there is a file somewhere I can use to recover it.
And if there is no way to recover, how can I completely save my workspace so this cannot happen again?
Also, is there a proper way to recover from an RStudio freeze without a hard reset?
It has been a while since I asked this question. I was never able to fully recover, but I switched to Rprojects which is the recommended way to use Rstudio.
Rprojects are stored in a folder and they remember all files and data from that project in that folder.
This did not help me with my initial problem, but projects prevent it from happening again. The hard part is moving a work-space to a project if it was not in a project to start.
Hi the first step of this article helped me entirely.
https://datacornering.com/how-to-restore-closed-unsaved-script-in-rstudio/
Basically, if on windows, go to C:\Users\xx\AppData\Local\RStudio\sources\s-xx and find a file with "-contents" at the end. This is your unsaved file.

RStudio server - Hangs when switching projects

I am currently running RStudio via a server installation that I only partially maintain. I am working with some fairly large data sets and models (> 9 million rows of 611 variables). When I try to switch projects, RStudio hangs when loading the project (it says "Switching projects to..." at the top) or, if it loads, takes forever.
RStudio works otherwise while attempting to switch projects, but menus and the like do not work.
I have searched thoroughly for a fix to no avail. How would I go about troubleshooting (or, ideally, fixing) the problem?
RStudio is running on a linux (Open SuSE) VM.
Thanks in advance.
EDIT: Per this thread: https://stackoverflow.com/a/15373596/3469671, I deleted .rstudio from my home directory and that seemed to free things up. Is there some setting I can change to facilitate the loading of larger projects?
Per this thread, I deleted .rstudio from my home directory and that seemed to free things up.
As a practice, I learned to stop saving my workspace while it was loaded with data and included steps within projects to save and load prepared data.

Resources