(The question is about RStudio but probably goes beyond that, so maybe it should get into generic...)
At the high level my question is about automatic saving of the image associated with the recession I'm working with --- and also a question about history management at the end of this topic.
A situation that I encountered way too many times is that when a R session crashes for one reason or another, I lose all the data that is in memory, that is data that stored in data frames, lists, etc, that I generated after the last call to save.image(). This is expected, especially if there is no way to access the rsession process even with a debugger and hence access its memory, but it costs me hours afterwards to regenerate all the data since the last call to save.image; I have roughly a 5Gb .RData file (without compression, that I avoid for a faster save/load process).
The bottom line is that whenever something like that happens, even if the session is "hung" after some command that I put in, and I am trying to abort the command that caused the problem, there is often no other way than aborting/killing the rsession process, even if I keep RStudio alive. The then is not being saved, and the .RDate remains the same as it was the last time I called save.image (or closed the project, which is usually weeks before the crash).
I wanted to check check with the community whether there is already a working solution that people are using. I looked for it in the forum as well as googling it but didn't find anything.
To be precise, what I am basically looking for is some kind of automated periodic saving of an image snapshot. Even if there is no way to achieve that, can I at least force saving it when the rsession is still alive but "hung" for hours --- but not yet terminated, and is just not accessible from the command line? Yesterday I had a session that was hung for hours --- even RStudio couldn't terminate it, and when I did it externally, it took RStudio another few hours to show me the "R session has terminated" window. I started thinking of complicated solution of having another background process that shares the memory with the rsession one, or some kind of a client-server solution, but I really hope I'm just missing something trivial and that there is an easy way to achieve that without going that far. I am working on a Mac if it is relevant.
That leads to my second question, about the RStudio (and rseesion) history mechanism:
Recovering from a situation like the one described above is highly mitigated with the exceptionally good history saving mechanism of RStudio; it saves me a few hours every time something like that happens, in the process of re-generate all the data that I lost. It would be really helpful if I can remove from history some commands after I ran them, that were incorrect or caused errors. That way I will not repeat these mistakes when regenerating the data --- but I also think that in general, it is sometimes helpful to remove a line from history so it will not be suggested at the command line when you use the history retrieval mechanism.
Any advice on these matters will be highly appreciated.
Thanks.