[R] Debug problem

Duncan Murdoch dmurdoch at pair.com
Wed Apr 21 04:04:57 CEST 2004


On Wed, 21 Apr 2004 00:47:55 +0000 (UTC), Gabor Grothendieck
<ggrothendieck at myway.com> wrote:


>Thanks.  Your hypothesis does seem likely.  In
>
>g <- f; environment(g) <- new.env()
>
>is there any way that I can automatically set g to have debugging 
>iff f has it?

undebug() gives a warning if the function doesn't have the debug flag
set, so it's possible to do it.  I'm new to the new signals in R, so
this might be a really ugly implementation, but here goes:

isbeingdebugged <- function(f) {
    if (is.function(f)) {
        result <- tryCatch(undebug(f), warning = function(w) 1)
	  result <- is.null(result)
	  if (result) debug(f)
	  result
    } else stop('Not a function')
}

copydebugstatus <- function(f, g) {
   if (isbeingdebugged(f)) debug(g)
   else if (isbeingdebugged(g)) undebug(g)
}

Duncan Murdoch




More information about the R-help mailing list