Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

How to cancel an Infinite Loop in R

I'm trying to get some code running in R on my MacBook Pro, and I made the mistake of writing an infinite loop. Normally, I'd just hit "esc" in order to terminate the running program. How do I cancel the infinite loop?

Posted on Nov 14, 2018 5:47 AM

Reply
Question marked as Best reply

Posted on Nov 14, 2018 9:18 AM

  • 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

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.


You should be able to run kill in terminal:

$ kill -2 pid

You can find the pid by running

$ps aux | grep exec/R

1 reply
Question marked as Best reply

Nov 14, 2018 9:18 AM in response to orok275

  • 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

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.


You should be able to run kill in terminal:

$ kill -2 pid

You can find the pid by running

$ps aux | grep exec/R

How to cancel an Infinite Loop in R

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.