From wdunlap at tibco.com  Thu Jul  7 20:53:39 2016
From: wdunlap at tibco.com (William Dunlap)
Date: Thu, 7 Jul 2016 11:53:39 -0700
Subject: [Rd] Detecting user interrupts in R_tryEval
In-Reply-To: <CABFfbXv9EQdJcNDpQiBhiwA78m2YH+tC1m6NXR2SgsoJp3+pFA@mail.gmail.com>
References: <CABFfbXv9EQdJcNDpQiBhiwA78m2YH+tC1m6NXR2SgsoJp3+pFA@mail.gmail.com>
Message-ID: <CAF8bMcaqeeqJtEcUd5PO3=z_EvhUP9mBn+W40wjOcGO8SuZjAQ@mail.gmail.com>

In R code tryCatch can detect the difference.  Hit control-C (on Unixen) or
Escape
(on Windows) to interrupt the long-running for loop and see that the
interrupt clause
gets called:

> z <- tryCatch(for(i in seq_len(1e8))log(exp(i/10)), error=function(e)e,
interrupt=function(e)e)
^C> dput(z)
structure(list(), class = c("interrupt", "condition"))



Bill Dunlap
TIBCO Software
wdunlap tibco.com

On Thu, Jul 7, 2016 at 10:18 AM, Jeroen Ooms <jeroen.ooms at stat.ucla.edu>
wrote:

> Is there any way to distinguish between an error and a user
> interruption in R_tryEval? In both cases the ErrorOccurred argument is
> set to 1. For my application I need a different action in case of a
> SIGINT.
>
> >From the source code I infer that R_tryEval basically wraps eval in
> R_ToplevelExec, which returns TRUE if fun returns normally, FALSE if
> it results in a jump to top level. However both an error and SIGINT
> result in a jump. Is there an alternative method, or some method of
> finding out which is the two happened after calling R_tryEval?
>
> One thing I tried is see if R_curErrorBuf() is empty. However this is
> unreliable because in the case of an interrupt, the error buffer
> sometimes contains some old error message.
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

	[[alternative HTML version deleted]]



[Rd] Detecting user interrupts in R_tryEval
William Dunlap