[R] how do you know which functions are being debugged?
Steve Lianoglou
mailinglist.honeypot at gmail.com
Fri Oct 23 20:57:23 CEST 2009
Hi,
On Oct 23, 2009, at 2:39 PM, Gabor Grothendieck wrote:
> On Fri, Oct 23, 2009 at 2:34 PM, Duncan Murdoch
> <murdoch at stats.uwo.ca> wrote:
>> On 10/23/2009 2:27 PM, Gabor Grothendieck wrote:
>>>
>>> I have often wanted to get such a list as well without having to
>>> write
>>> code myself. If a function which automatically iterated over all
>>> possible objects and listed out the ones that being debugged were
>>> available in the core it would be useful. Even if its slow this
>>> would
>>> be used at debug time and not a production time so it would not be
>>> too
>>> bad. Even a heuristic that checked likely locations, e.g. just the
>>> global environment, but not all locations might be useful.
>>
>> If you look at the code in setBreakpoint, it does a search for
>> functions in
>> lots of places (but not everywhere). You could start from that.
>>
>> Generally speaking, it's quite hard to think of a way to express
>> what the
>> answer would look like to a perfectly general function like you're
>> asking
>> for. Suppose a function lives in the parent environment of the
>> environment
>> of an expression that was returned in the result of a call to lm
>> that is a
>> local variable in the function that called the function where you
>> are asking
>> the question: how would you return that as an answer??? In a
>> language with
>> pointers, you'd just return a pointer to it, but R doesn't have
>> those.
>
> I agree its problematic but it would still be useful since after you
> have debugged a number of functions its easy to forget which ones are
> being debugged.
If this is something you just want to use on your own functions that
are set to `debug`, why not just make write a debug wraps the
base::debug and does some keeps track of which functions you're
debugging in some global environment variable (of your creation).
You should probably use something beside "substitute" here, but:
R> .DLIST <- character()
R> debug <- function(fun, text="", condition=NULL) {
.DLIST <<- c(.DLIST, substitute(fun))
base::debug(fun, text=text, condition=condition)
}
R> myfun <- function(something) {
a <- length(something)
b <- sum(something)
b
}
R> debug(myfun)
R> debug(myfun)
R> .DLIST
[[1]]
myfun
R> myfun(1:10)
debugging in: myfun(1:10)
debug: {
a <- length(something)
b <- sum(something)
b
}
Browse[2]> n
debug: a <- length(something)
Browse[2]> n
debug: b <- sum(something)
Browse[2]> n
debug: b
Browse[2]> n
exiting from: myfun(1:10)
[1] 55
You can define your own undebug function accordingly.
Would that do what you want?
-steve
--
Steve Lianoglou
Graduate Student: Computational Systems Biology
| Memorial Sloan-Kettering Cancer Center
| Weill Medical College of Cornell University
Contact Info: http://cbio.mskcc.org/~lianos/contact
More information about the R-help
mailing list