[Rd] recover and "called from" information

From: Romain Francois <romain.francois_at_dbmail.com>
Date: Tue, 27 Oct 2009 17:51:22 +0100


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

-- 
Romain Francois
Professional R Enthusiast
+33(0) 6 28 91 30 30
http://romainfrancois.blog.free.fr
|- http://tr.im/BcPw : celebrating R commit #50000
|- http://tr.im/ztCu : RGG #158:161: examples of package IDPmisc
`- http://tr.im/yw8E : New R package : sos

______________________________________________
R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Received on Tue 27 Oct 2009 - 16:53:25 GMT

This archive was generated by hypermail 2.2.0 : Mon 02 Nov 2009 - 02:30:19 GMT