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

From: Nick Sabbe <nick.sabbe_at_ugent.be>
Date: Tue, 06 Sep 2011 11:49:55 +0200

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

R-devel_at_r-project.org mailing list
Received on Tue 06 Sep 2011 - 09:52:38 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

All messages

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 06 Sep 2011 - 16:20:28 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.

list of date sections of archive