Skip to content
Prev 6950 / 15075 Next

How to interrupt an R process that hangs

On Mar 15, 2010, at 16:20 , Matthew Keller wrote:

            
How could I?

 > for (i in 1:100000){
+ a <- matrix(rnorm(100000*100000),ncol=100000)
+ b <- svd(a)}
Error in rnorm(1e+05 * 1e+05) : invalid arguments
In addition: Warning message:
In rnorm(1e+05 * 1e+05) : NAs introduced by coercion

The only way to run that code at all is to scale it down, e.g.

 >  for (i in 1:100000){
+ a <- matrix(rnorm(1000*1000),ncol=1000)
+ b <- svd(a)
+ }

and when interrupted it comes back within 5s on my Mac ...

I get your general point, but the fact remains that you cannot  
interrupt native code unless it has provisions to do so. The reason is  
that it is impossible to cleanup native code properly (i.e if the  
author did not think of it) so R allows interruption only if the code  
tells R that it is safe to do so.
.. if you are in C code, see above. Otherwise it interrupts the R code  
(and so doe ^C or pushing the Stop button etc....).

Cheers,
Simon