Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to terminate a plotting job in Rstudio

Tags:

r

rstudio

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).

like image 916
WetlabStudent Avatar asked Dec 23 '13 00:12

WetlabStudent


People also ask

How to clear the last plot in RStudio?

In RStudio, you can use x11 (), windows () or quartz () (depending on your device) before each plot. Then call dev.off () to clear last plot.

Is it possible to kill a script in RStudio?

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.

How do I stop a running R script in R?

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.

How to interrupt a loop in RStudio?

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.


1 Answers

Re-posting my comment as an answer since it seems to have solved your problem.

  1. Save early, save often, cry less.
  2. Try clicking the little red stop icon above the console panel (unlikely to work if you've done all that you've done already).
  3. Try copy/pasting the script out to a text editor.
  4. Try killing just the rsession process through your OS (might leave RStudio open). 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.
like image 111
Ari B. Friedman Avatar answered Oct 11 '22 13:10

Ari B. Friedman