Say I enter the following commands into the console in Rstudio
x=seq(0,1e11, by=.01)
plot(x,sin(x))
Clearly this is a very silly thing to do. But my question is how do you terminate this process? I couldn't find this answered anywhere.
Attempted solutions: pressing ctrl+q, pressing esc, going to session->interupt R, going to session->terminate R. Nothing seems to work. This seems to be specific to plotting, for example if you run a stupidly large loop, most of the above options seem to work as expected.
Ideally I'd like a solution that doesn't lose the R script I have been working on in the console (as I haven't saved it in awhile).
In RStudio, you can use x11 (), windows () or quartz () (depending on your device) before each plot. Then call dev.off () to clear last plot.
The good news is that RStudio is often pretty smart about backing up working copies of scripts, so you might find it's still there even if you have to kill the whole program. Entering dev.null () in the console will kill any plots and I find it's less likely to crash RStudio than some of the options given by Ari B. Friedman.
Example: Keyboard Shortcut to Stop Running R Script in RStudio The shortcut to interrupt a running process in R depends on the R software and the operating system you are using. However, if you are using RStudio on a Windows computer, you can usually use Esc to stop a currently executing R script.
Then, we can press Esc to interrupt the loop. As you can see based on the previous output of the RStudio console, in this example we pressed Esc after approx. 11 seconds. Please note that the Esc command might not work in case you are running a memory-intensive process.
Re-posting my comment as an answer since it seems to have solved your problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With