[R] determining a parent function name

Sundar Dorai-Raj sundar.dorai-raj at pdf.com
Wed May 30 23:53:28 CEST 2007


Hi, All,

I'm writing a wrapper for stop that produces a popup window using tcltk. 
Something like:

error <- function(...) {
   msg <- paste(..., sep = "")
   if(!length(msg)) msg <- ""
   if(require(tcltk, quiet = TRUE)) {
     tt <- tktoplevel()
     tkwm.title(tt, "Error")
     tkmsg <- tktext(tt, bg = "white")
     tkinsert(tkmsg, "end", sprintf("Error in %s: %s", "???", msg))
     tkconfigure(tkmsg, state = "disabled", font = "Tahoma 12",
                 width = 50, height = 3)
     tkpack(tkmsg, side = "bottom", fill = "y")
   }
   stop(msg)
}

But, I would like to know from which function error() is called. For 
example, if I have

foo <- function() stop()
bar <- function() error()
 > foo()
Error in foo() :
 > bar()
Error in error() :

and in the tk window I get

Error in ???:

I need the output of bar (in the tk window only) to be

Error in bar():

then it's clear where error is called. I'm not worried about the output 
bar() produces on the console.

Hope this makes sense.

Thanks,

--sundar



More information about the R-help mailing list