One of my RStudio projects stalls even before I've run any code or loaded any packages or data. I can edit scripts but it won't save them and it won't run code in the console. I am still able to use R from the terminal. After some time (in the range of an hour or so), multiple dialog boxes will pop up with the message Unable to establish connection with R session. I've seen a similar thing before when loading big datasets or running something computationally intensive but never before I've even run any code or loaded any data.
My other Projects don't seem to have the same problem.
I've also filed an issue here on the RStudio github with some screenshots and log files in case that's helpful.
The solution was to update the data.table package. See the issue I filed or this thread on RStudio community
Related
I use R, Rstudio and Rcpp and I spent over a week debugging some code, that was just giving errors and warnings in unexpected places, in some cases with direct sample code from online or package documentation.
I often restart the R session or Rstudio if there are obvious problems and they usually go away.
But this morning it was really bad to the point were basic R commands would fail and restarting R did nothing. I closed all the Rstudio sessions and restarted the machine for good measure, (which was unnecessary).
When it came back and I re-loaded the sessions everything seems to be working.
Even the some rcpp code I was working on for weeks with outside packages will now compile and run where it gave gibberish errors before.
I have known for a while that R needs to be restarted once in a while, but I know it when basic functions don't run, how can I know earlier.
I am looking for a good general resource or function that can tell me I need to restart because something is not running right. I would be nice if I can also know what to restart.
Whether the R session, the GUI such as Rstudio, all sessions and GUIs or a full machine restart.
For as long as I have been dabbling with or actually using R (ie more than two decades), it has always been recommended to start a clean and fresh session.
Which is why I prefer to work on command-line for tests. When you invoke R, or Rscript, or, in my case, r (from littler) you know you get a fresh session free of possible side-effects. By keeping these tests to the command-line, my main sessions (often multiple instances inside Emacs via ESS, possibly multiple RStudio sessions too) are less affected.
Even RStudio defaults to 'install and restart' when you rebuild a package.
(I will note that a certain development package implies you could cleanly unload a package. That has been debated at length, and I think by now even its authors qualify that claim. I don't really know or case as I don't use it, having had established workflows before it appeared.)
And to add: You almost never need to restart the computer. But a fresh clean process is a something to use often. Your computer can create millions of those for you.
I am unable to load an R project and I am getting an error: Error occurred while checking for updates. Unable to establish a connection with R session with R studio. I am using large data sets inside that projects which might be causing this issue. Is there a way I could log in from the terminal and remove some datasets from the workspace. Can someone help how I can log in?
It sounds like you're auto-saving the workspace to .RData. It's usually not a problem (though still not advised) to do so with small-ish data sets/objects in the workspace but it's almost deadly to use this setting if you work with large data sets/objects often.
Disable the Restore .RData into workspace at startup setting in RStudio preferences and also set Save workspace to .RData on exit to Never.
Hunt down all the .RData files in your various working directories and delete them, too.
I had the same problem. And the above proposed strategy did not work well. However, having anaconda installed in my PC I downloaded Rstudio on that platform. Contrarily to the other Rstudio standalone version, Rstudio in anaconda works well. I do not know why, but in case of need you can smash out your Rstudio without deleting your files and use the Rstudio on the anaconda platform. Just to have another point of view!
I've recently run into an issue when using Rstudio-Server that multiple sessions are spawned instead of a single session. In my case (see below) five sessions are created instead of one. This happens even after trying the normal solutions: deleting ~/.rstudio, clearing .GlobalEnv, and restarting R. Note, there is no spawning issue when using the R command prompt.
My belief about the source of this problem is that it is due to a prematurely terminated mclapply. Here are the relevant docs from the parallel package. (discovered after the fact)
It is strongly discouraged to use these functions in GUI or embedded environments, because it leads to several processes sharing the same GUI which will likely cause chaos (and possibly crashes). Child processes should never use on-screen graphics devices.
At least one other person has had the same error as me but there is no documented solution that I can find. As the warning has already been ignored, I would appreciate any pointers that can help me get untangled.
Edit:
I am still encountering the error but was able to catch the ephemeral script sourcing issue that I believe is causing this problem. Unfortunately, I don't know what other files are being sourced and therefore what settings need to be changed. Grrrrr.....
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.
I usually open the R console all day long, but sometimes I need to clean my history and my workspace's background so that I can test functions or load new data.
I'm wondering whether there is an easier way to use a command line in .Rprofile so that I can refresh the R console without quitting or rebooting my current session.
What I have usually done for this is to q() without saving and then start R again and clean the History. I think somebody here might be able to give me some better suggestions.
Thanks in advance.
For what concerns history, in UNIX-like systems (mine is Debian) this command refreshes it
loadhistory("")
However, as said in comments, loadhistory seems to be platform-dependent.
Check your ?loadhistory if present on your platform. Mine says:
There are several history mechanisms available for the different
R consoles, which work in similar but not identical ways. There
are separate versions of this help file for Unix and Windows.
The functions described here work on Unix-alikes under the
readline command-line interface but may not otherwise (for
example, in batch use or in an embedded application)