From nick.sabbe at ugent.be  Tue Sep  6 11:49:55 2011
From: nick.sabbe at ugent.be (Nick Sabbe)
Date: Tue, 6 Sep 2011 11:49:55 +0200
Subject: [Rd] do.call and sys.call: suggestion for improval?
Message-ID: <039101cc6c7a$54f31b10$fed95130$@sabbe@ugent.be>

Hi all.

I'll start by introducing the origin of the problem, although it appears to
me that it goes beyond my specific setting.

I'm currently working on a method for finding the 'lowest named function
call' on the call stack. I am aware that the name of a function is not
uniquely defined, but for most reasonable cases, the intended name can be
easily induced.
You can see some of the specific issues here:
http://stackoverflow.com/questions/7307987/logging-current-function-name if
you like.

After some fidgeting and great help by Andrie (see the SO link; sorry I
don't know his last name), it works rather well.

There are, however, issues wrt do.call.
Typical usage would then be: do.call(some.named.function, some.list)
Now, when I look at the stackframe inside this some.named.function (or a
function that is called from it), more or less like this:
funcs <- sapply(2+1:sys.nframe(), function(i) sys.call(sys.parent(n=i))[[1]]
)
I get strange results: contrary to the 'normal' named function calls, I
don't get the function name, but I get back a closure, that is really just
(a copy of) my original some.named.function. On the other hand, the do.call
call itself is _not_ on the stackframe.

The good news is: this makes do.call still reasonably identifiable (I'm
willing to assume this closure returning in sys.call is unique to do.call).
The bad news is, that there is, as of now, no way to retrieve the name of
the function as it was passed to do.call.

So, my questions:
* why is the do.call call itself not on the stackframe? (I could hope to
extract the name there somehow)
* why is the result of sys.call not consistent with normal function calls? I
am aware of the warning in the help for do.call that "the precise semantics
are currently undefined and subject to change", but I was hoping this could
be (easily) altered? I believe it is in the best interest of the R community
that calls through do.call are as close as possible to 'normal' calls, and
this is rather a big difference.
* does anybody have other suggestions on how to obtain the name of the
function in that case? I'm also willing to accept that I may need to change
my own implementation after 'the specific semantics' change somewhere in the
future.

If there is a reason behind the difference (besides something like "it's not
so easy to code that"), I would be very interested in learning about it.
Also, if I have completely misunderstood how things work, I will gladly
accept redirections and/or flames.

Thanks in advance (well, not for potential flames),

Nick Sabbe
--
ping: nick.sabbe at ugent.be
link: http://biomath.ugent.be
wink: A1.056, Coupure Links 653, 9000 Gent
ring: 09/264.59.36

-- Do Not Disapprove



[Rd] do.call and sys.call: suggestion for improval?
Nick Sabbe