From murdoch at stats.uwo.ca  Mon Nov  2 01:57:27 2009
From: murdoch at stats.uwo.ca (Duncan Murdoch)
Date: Sun, 01 Nov 2009 19:57:27 -0500
Subject: [Rd] recover and "called from" information
In-Reply-To: <4AE7250A.3090209@dbmail.com>
References: <4AE7250A.3090209@dbmail.com>
Message-ID: <4AEE2E77.5080903@stats.uwo.ca>

I've put a fix for this in place in R-devel now.  It required adding 
another parameter to browser(), so I'd like to test it out a while 
before backporting it to 2.10.0 patched.

Please give it a try, and let me know if you notice anything wrong.

Duncan Murdoch

On 27/10/2009 12:51 PM, Romain Francois wrote:
> Hello,
> 
> When using recover, the called from information is always "eval(expr, 
> envir, enclos)", which is not particularly useful.
> 
>  > f <- function( ){ g <- function(){ stop( "ouch") }; g() }
>  > options( error = recover )
>  > f()
> Error in g() : ouch
> 
> Enter a frame number, or 0 to exit
> 
> 1: f()
> 2: g()
> 
> Selection: 1
> Called from: eval(expr, envir, enclos)
> 
> 
> I'm using the following heuristic to guess if this was called from 
> recover and grab the actual call, and was wondering if something similar 
> could/should be integrated into R:
> 
> getcall <- function(){
> 	calls <- sys.calls()
> 	calls <- calls[ -length(calls) ]
> 	funs <- sapply( calls, function(x) as.character(x)[1L] )
> 	frames <- sys.frames()
> 	frames <- frames[ -length(frames) ]
> 	nc <- length(calls)
> 	
> 	if( nc >= 3L &&
> 		identical( tail(funs, 2L ), rep("eval", 2L) ) &&
> 		identical(
> 			paste( as.character( calls[[ nc - 1L ]] ), collapse = "--" ),
> 			"eval--quote(browser())--sys.frame(which)" )
> 			) {
> 		
> 		w <- get( "which", sys.frame(nc- 2L ), inherits = FALSE )
> 		if( typeof( w ) == "integer" && length(w) == 1L ){
> 			return( calls[[w]] )
> 		}
> 		
> 	}
> 	calls[[nc]]
> 	
> }
> 
> I'd be happy to work on an internal version instead of this one in R.
> 
> Romain
> 
>



[Rd] recover and "called from" information
Duncan Murdoch