[R] [R-SIG-Mac] How to interrupt an R process that hangs

Duncan Murdoch murdoch at stats.uwo.ca
Mon Mar 15 20:08:29 CET 2010


On 15/03/2010 2:42 PM, Adam D. I. Kramer wrote:
> +1--this is the single most-annoying issue with R that I know of.
>
> My usual solution, after accomplishing nothing as R spins idly for a couple
> hours, is to kill the process and lose any un-saved work.  save.history() is
> my friend, but is a big delay when you work with big data sets as I do, so I
> don't run it after every command.
>
> I have cc'd r-help here, however, because I experience this problem with
> non-OSX R as well...when I run it in Linux or from the OSX command-line (I
> compile R for Darwin without aqua/R-framework), the same thing happens.
>
> Is there some way around this? Is this a known problem?
>
> Google searching suggests no solution, timeline, or anything, but the
> problem has been annoying users for at least twelve years:
> http://tolstoy.newcastle.edu.au/R/help/9704/0151.html
>   

In the Windows GUI, the Esc key sets a flag which will cause 
computations to cease the next time the flag is checked. Unix-like 
systems do the same thing through signals.  SIGINT should eventually 
stop the computation.  How you send one of those in the OSX gui I don't 
know, but it works on a Linux system to run the command

 kill -s INT <PID>

where <PID> is the R process ID.  (Ctrl-C also works in that situation, 
but I'm assuming it's not available to you.)

In either case, I think it's possible to still end up in an unending 
loop, if you're doing some computation that never returns to the R 
evaluator.  (This might not be true in Unix-like systems.  They'll 
probably process the signal faster than Windows will see the Esc key, 
but I don't think that causes an immediate break when external code
is running.)  The key is to write your external code to check for user 
interrupts every now and then.

Duncan Murdoch
> Cordially,
> Adam
>
> On Mon, 15 Mar 2010, Matthew Keller wrote:
>
> > HI all,
> >
> > Apologies for this question. I'm sure it's been asked many times, but
> > despite 20 minutes of looking, I can't find the answer. I never use
> > the GUI, I use emacs, but my postdoc does, so I don't know what to
> > tell her about the following:
> >
> > Occasionally she'll mess up in her code and cause R to hang
> > indefinitely (e.g., R is trying to do something that will take days).
> > In these situations, is there an option other than killing R (and the
> > work you've done on your script to that point)?
> >
> > Thank you,
> >
> > Matthew Keller
> >
> >
> > -- 
> > Matthew C Keller
> > Asst. Professor of Psychology
> > University of Colorado at Boulder
> > www.matthewckeller.com
> >
> > _______________________________________________
> > R-SIG-Mac mailing list
> > R-SIG-Mac at stat.math.ethz.ch
> > https://stat.ethz.ch/mailman/listinfo/r-sig-mac
> >
>
> _______________________________________________
> R-SIG-Mac mailing list
> R-SIG-Mac at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/r-sig-mac
>



More information about the R-help mailing list