Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I interrupt a running code in R with a keyboard command?

Tags:

r

Can anyone tell how can I interrupt a running script in R?

Let's say I have an infinite loop or some other problem, and I want to stop the script from running. Is there a keyboard command that does that?

If it helps any, in Python it is Ctrl + c. I tried that in R, and it didn't work :).

I did some search for this seemingly simple question, but could not find the answer.

Thanks in advance.

like image 692
Akavall Avatar asked Dec 03 '11 19:12

Akavall


People also ask

How do I stop a run command in R?

In R Studio, Rgui, and R. APP, pressing the Esc key interrupts the running code. R Studio also offers a Stop button and a menu option to stop running code with the mouse. In the R command-line interface, the Ctrl + C command stops the execution of the code.

How do I run an R code on my keyboard?

6.1 Running code The key to using the script editor effectively is to memorise one of the most important keyboard shortcuts: Cmd/Ctrl + Enter. This executes the current R expression in the console.


2 Answers

Self Answer (pretty much summary of other's comments and answers):

  • In RStudio, Esc works, on windows, Mac, and ubuntu (and I would guess on other linux distributions as well).

  • If the process is ran in say ubuntu shell (and this is not R specific), for example using:

    Rscript my_file.R 

    Ctrl + c kills the process

    Ctrl + z suspends the process

  • Within R shell, Ctrl + C kills helps you escape it

like image 117
Akavall Avatar answered Sep 24 '22 00:09

Akavall


Control-C works, although depending on what the process is doing it might not take right away.

If you're on a unix based system, one thing I do is control-z to go back to the command line prompt and then issue a 'kill' to the process ID.

like image 21
geoffjentry Avatar answered Sep 24 '22 00:09

geoffjentry