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

后端 未结 4 2055
广开言路
广开言路 2020-12-02 12:12

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

相关标签:
4条回答
  • 2020-12-02 12:13

    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.

    0 讨论(0)
  • 2020-12-02 12:21

    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

    0 讨论(0)
  • 2020-12-02 12:36

    Try out Ctrl + z But it will kill the process, not suspend it.

    0 讨论(0)
  • 2020-12-02 12:36

    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!

    0 讨论(0)
提交回复
热议问题