[R] determining a parent function name

Sundar Dorai-Raj sundar.dorai-raj at pdf.com
Thu May 31 23:22:33 CEST 2007


Ismail Onur Filiz said the following on 5/31/2007 1:03 PM:
> Sorry for replying to myself, but:
> 
> On Thursday 31 May 2007 12:23:12 Ismail Onur Filiz wrote:
>> Hi,
>>
>> On Wednesday 30 May 2007 14:53:28 Sundar Dorai-Raj wrote:
>>> 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)
>>> }
>> as.character(sys.call(-1)[[1]]) works for me.
> 
> you can furthermore do:
> 
> options(error=error)
> 
> and remove the stop(msg) call in the last line of the function. Then your 
> function will become the error handler.
> 
> Best...


Thanks, with the minor change to sys.call(-2) that does exactly what I want.

thanks,

--sundar



More information about the R-help mailing list