[Rd] delayedAssign and interrupts

Duncan Murdoch murdoch at stats.uwo.ca
Fri May 19 16:15:20 CEST 2006


On 5/19/2006 9:54 AM, Roger D. Peng wrote:
> I noticed something recently that I thought was odd:
> 
> delayedAssign("x", { Sys.sleep(5); 1 })
> x  ## Hit Ctrl-C within the first second or 2
> 
> gives me:
> 
>  > delayedAssign("x", { Sys.sleep(5); 1 })
>  > x  ## Hit Ctrl-C within the first second or two
> 
>  > x
> Error: recursive default argument reference
>  >
> 
> My only problem here is that now I'm stuck---there's no way to recover whatever 
> 'x' was supposed to be (i.e. 1).
> 
> In reality, I want 'x' to be a promise to load a moderately large data object. 
> But if I (or a user) Ctrl-C's during the load I'll have to start from scratch. 
> Is there anyway to recover the promise (or the value of the expression) in case 
> of an interrupt?

I don't know of one.  Normally substitute(x) is supposed to retrieve the 
  promise expression, but by a strange quirk of history, it does not 
work when x is in .GlobalEnv.

I'd say the behaviour you're seeing is a bug.  If I do

 > x <- 2
 > x <- {Sys.sleep(1); 1}  # Break before complete

 > x
[1] 2

nothing is changed about x.  I would think the same thing should happen 
when x is a promise:  if the evaluation of the promised expression 
fails, the promise should not be changed.

Duncan Murdoch



More information about the R-devel mailing list