How can I interrupt a running code in R with a keyboard command?
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.
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 processCtrl + z
suspends the processWithin R shell,
Ctrl + C
kills helps you escape it
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.
Try out Ctrl + z But it will kill the process, not suspend it.
I know this is old, but I ran into the same issue. I'm on a Mac/Ubuntu and switch back and forth. What I have found is that just sending a simple interrupt signal to the main R process does exactly what you're looking for. I've ran scripts that went on for as long as 24 hours and the signal interrupt works very well. You should be able to run kill in terminal:
$ kill -2 pid
You can find the pid by running
$ps aux | grep exec/R
Not sure about Windows since I'm not ever on there, but I can't imagine there's not an option to do this as well in Command Prompt/Task Manager
Hope this helps!
'Development Tip' 카테고리의 다른 글
How to block calls in android (0) | 2020.11.05 |
---|---|
Indoor Positioning System based on Gyroscope and Accelerometer (0) | 2020.11.05 |
Javascript - Storing function in object - bad practice? (0) | 2020.11.05 |
How to run a SQL query on an Excel table? (0) | 2020.11.05 |
Python: import module from another directory at the same level in project hierarchy (0) | 2020.11.05 |