[R] get caller's name

Duncan Murdoch murdoch.duncan at gmail.com
Fri Feb 4 15:02:49 CET 2011


On 03/02/2011 10:27 AM, Ernest Adrogué wrote:
> Hi,
> Suppose a function that checks an object:
>
> stop.if.dims<- function(x) {
>    if (! is.null(dim(x))) {
>      stop("cannot handle dimensional data")
>    }
> }
>
> This would be used by other functions that can only work with
> dimensionless objects. The problem is the error message would need to
> include the name of the function that called stop.if.dims, so that the
> user knows which function got an argument that was incorrect.
>
> How do I do this? Or maybe there is another way...

I see you have the answer you wanted, but I'd suggest you don't need 
this:  the user should just use traceback() after the error to see the 
full call stack.  Perhaps it's not the caller that's the problem, but 
the caller of the caller...

Duncan Murdoch



More information about the R-help mailing list