Re: [R] how do you know which functions are being debugged?

2009-10-23 Thread Gabor Grothendieck
On Fri, Oct 23, 2009 at 7:06 PM, Duncan Murdoch  wrote:
> Gabor Grothendieck wrote:
>>
>> On Fri, Oct 23, 2009 at 2:52 PM, Duncan Murdoch 
>> wrote:
>>
>>>
>>> On 10/23/2009 2:49 PM, Andrew Yee wrote:
>>>

 Thanks everyone for the responses.  As a suggestion, wouldn't it be
 useful,
 that when you run isdebugged() without any parameters, it would just
 report
 back the functions that are being flagged for debugging?

>>>
>>> Could you give an example of what the answer would look like?  Not all
>>> functions have names, not all names are unique, ...
>>>
>>>
>>
>> One could use the formal argument list of the function, i.e. the
>> output of args, when there is no notion of name since that is always
>> available.
>>
>
> It would actually be easier to return a copy of the whole function.  But

That`s already done when you enter debugging and I find it quite
annoying particularly when you have large functions interrupting the
flow.  I wish there were some way to limit this.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] how do you know which functions are being debugged?

2009-10-23 Thread Steve Lianoglou

Sweet Jesus ... I just read what I wrote earlier ...

On Oct 23, 2009, at 2:57 PM, Steve Lianoglou wrote:
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).


This has to win for one of my most lucid moments.

I feel like I should publicly apologize for letting such an  
abomination out of its cage. Hopefully the code I sent explained what  
my feeble attempt at "human communication" didn't ... yeesh!


Sorry :-)

-steve


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


--
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

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] how do you know which functions are being debugged?

2009-10-23 Thread Duncan Murdoch

Gabor Grothendieck wrote:

On Fri, Oct 23, 2009 at 2:52 PM, Duncan Murdoch  wrote:
  

On 10/23/2009 2:49 PM, Andrew Yee wrote:


Thanks everyone for the responses.  As a suggestion, wouldn't it be
useful,
that when you run isdebugged() without any parameters, it would just
report
back the functions that are being flagged for debugging?
  

Could you give an example of what the answer would look like?  Not all
functions have names, not all names are unique, ...




One could use the formal argument list of the function, i.e. the
output of args, when there is no notion of name since that is always
available.
  


It would actually be easier to return a copy of the whole function.  But 
this wouldn't tell you how to turn off debugging:  for example, if an 
environment captured a copy of a function with the debugging bit set, 
then you really need to know where it was found, not just what was 
found.  It's tricky to put together examples of this because debug(f) 
doesn't act like a normal function, but here's an example showing some 
of the weird behaviour:


f <- function(x) x^2
debug(f)
g <- f

# now both g and f have the debug bit set.  Should both be returned by 
the "showDebugged" function?


undebug(f)

# that unset both.  Now undebug(g) would give a warning.

debug(f)

# that set both

f <- function(x) x^2

# Now g has it set, but f doesn't.

In this example, I was doing explicit assignments, but if f had been 
passed as an argument to a function, an implicit assignment would be 
made to the local variable holding it, and the same sort of behaviour 
would result.  I think this would be very confusing, and not 
particularly helpful, in lots of cases.


I think Steve's suggestion is really the right way to go:  if you're 
going to be setting lots of debug flags, then keep track of them 
yourself, and use your records to unset them. 


Duncan Murdoch

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] how do you know which functions are being debugged?

2009-10-23 Thread Gabor Grothendieck
On Fri, Oct 23, 2009 at 2:52 PM, Duncan Murdoch  wrote:
> On 10/23/2009 2:49 PM, Andrew Yee wrote:
>>
>> Thanks everyone for the responses.  As a suggestion, wouldn't it be
>> useful,
>> that when you run isdebugged() without any parameters, it would just
>> report
>> back the functions that are being flagged for debugging?
>
> Could you give an example of what the answer would look like?  Not all
> functions have names, not all names are unique, ...
>

One could use the formal argument list of the function, i.e. the
output of args, when there is no notion of name since that is always
available.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] how do you know which functions are being debugged?

2009-10-23 Thread Steve Lianoglou

Hi,

On Oct 23, 2009, at 2:39 PM, Gabor Grothendieck wrote:

On Fri, Oct 23, 2009 at 2:34 PM, Duncan Murdoch  
 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

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] how do you know which functions are being debugged?

2009-10-23 Thread Duncan Murdoch

On 10/23/2009 2:49 PM, Andrew Yee wrote:

Thanks everyone for the responses.  As a suggestion, wouldn't it be useful,
that when you run isdebugged() without any parameters, it would just report
back the functions that are being flagged for debugging?


Could you give an example of what the answer would look like?  Not all 
functions have names, not all names are unique, ...


Duncan Murdoch


Andrew

On Fri, Oct 23, 2009 at 2:12 PM, Yihui Xie  wrote:


Oops... I forgot to mention that 'envir' (or 'pos') should be
specified in ls()/get() in my last reply if you are looking for
debugged functions in environments other than ".GlobalEnv".

Regards,
Yihui
--
Yihui Xie 
Phone: 515-294-6609 Web: http://yihui.name
Department of Statistics, Iowa State University
3211 Snedecor Hall, Ames, IA



On Fri, Oct 23, 2009 at 1:02 PM, Duncan Murdoch 
wrote:
> On 10/23/2009 1:28 PM, Andrew Yee wrote:
>>
>> This is kind of a dumb question:  I know you can use isdebugged() to
find
>> out if a specific function is flagged for debugging, but is there a way
to
>> list all the functions that are flagged for debugging?
>
> No, R doesn't keep any master list, it sets a flag in each one.  So you
> could iterate over all visible objects to find the ones that have the
flag
> set (and this is quite slow, there are a lot of places to look), but
there
> would always be the chance that one was hiding somewhere you didn't look.
>
> Duncan Murdoch
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>





__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] how do you know which functions are being debugged?

2009-10-23 Thread Andrew Yee
Thanks everyone for the responses.  As a suggestion, wouldn't it be useful,
that when you run isdebugged() without any parameters, it would just report
back the functions that are being flagged for debugging?
Andrew

On Fri, Oct 23, 2009 at 2:12 PM, Yihui Xie  wrote:

> Oops... I forgot to mention that 'envir' (or 'pos') should be
> specified in ls()/get() in my last reply if you are looking for
> debugged functions in environments other than ".GlobalEnv".
>
> Regards,
> Yihui
> --
> Yihui Xie 
> Phone: 515-294-6609 Web: http://yihui.name
> Department of Statistics, Iowa State University
> 3211 Snedecor Hall, Ames, IA
>
>
>
> On Fri, Oct 23, 2009 at 1:02 PM, Duncan Murdoch 
> wrote:
> > On 10/23/2009 1:28 PM, Andrew Yee wrote:
> >>
> >> This is kind of a dumb question:  I know you can use isdebugged() to
> find
> >> out if a specific function is flagged for debugging, but is there a way
> to
> >> list all the functions that are flagged for debugging?
> >
> > No, R doesn't keep any master list, it sets a flag in each one.  So you
> > could iterate over all visible objects to find the ones that have the
> flag
> > set (and this is quite slow, there are a lot of places to look), but
> there
> > would always be the chance that one was hiding somewhere you didn't look.
> >
> > Duncan Murdoch
> >
> > __
> > R-help@r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
> >
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] how do you know which functions are being debugged?

2009-10-23 Thread Gabor Grothendieck
On Fri, Oct 23, 2009 at 2:34 PM, Duncan Murdoch  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.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] how do you know which functions are being debugged?

2009-10-23 Thread Duncan Murdoch

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.


Duncan Murdoch



On Fri, Oct 23, 2009 at 2:02 PM, Duncan Murdoch  wrote:

On 10/23/2009 1:28 PM, Andrew Yee wrote:


This is kind of a dumb question:  I know you can use isdebugged() to find
out if a specific function is flagged for debugging, but is there a way to
list all the functions that are flagged for debugging?


No, R doesn't keep any master list, it sets a flag in each one.  So you
could iterate over all visible objects to find the ones that have the flag
set (and this is quite slow, there are a lot of places to look), but there
would always be the chance that one was hiding somewhere you didn't look.

Duncan Murdoch

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.



__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] how do you know which functions are being debugged?

2009-10-23 Thread Gabor Grothendieck
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.

On Fri, Oct 23, 2009 at 2:02 PM, Duncan Murdoch  wrote:
> On 10/23/2009 1:28 PM, Andrew Yee wrote:
>>
>> This is kind of a dumb question:  I know you can use isdebugged() to find
>> out if a specific function is flagged for debugging, but is there a way to
>> list all the functions that are flagged for debugging?
>
> No, R doesn't keep any master list, it sets a flag in each one.  So you
> could iterate over all visible objects to find the ones that have the flag
> set (and this is quite slow, there are a lot of places to look), but there
> would always be the chance that one was hiding somewhere you didn't look.
>
> Duncan Murdoch
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] how do you know which functions are being debugged?

2009-10-23 Thread Yihui Xie
Oops... I forgot to mention that 'envir' (or 'pos') should be
specified in ls()/get() in my last reply if you are looking for
debugged functions in environments other than ".GlobalEnv".

Regards,
Yihui
--
Yihui Xie 
Phone: 515-294-6609 Web: http://yihui.name
Department of Statistics, Iowa State University
3211 Snedecor Hall, Ames, IA



On Fri, Oct 23, 2009 at 1:02 PM, Duncan Murdoch  wrote:
> On 10/23/2009 1:28 PM, Andrew Yee wrote:
>>
>> This is kind of a dumb question:  I know you can use isdebugged() to find
>> out if a specific function is flagged for debugging, but is there a way to
>> list all the functions that are flagged for debugging?
>
> No, R doesn't keep any master list, it sets a flag in each one.  So you
> could iterate over all visible objects to find the ones that have the flag
> set (and this is quite slow, there are a lot of places to look), but there
> would always be the chance that one was hiding somewhere you didn't look.
>
> Duncan Murdoch
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] how do you know which functions are being debugged?

2009-10-23 Thread Duncan Murdoch

On 10/23/2009 1:28 PM, Andrew Yee wrote:

This is kind of a dumb question:  I know you can use isdebugged() to find
out if a specific function is flagged for debugging, but is there a way to
list all the functions that are flagged for debugging?


No, R doesn't keep any master list, it sets a flag in each one.  So you 
could iterate over all visible objects to find the ones that have the 
flag set (and this is quite slow, there are a lot of places to look), 
but there would always be the chance that one was hiding somewhere you 
didn't look.


Duncan Murdoch

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] how do you know which functions are being debugged?

2009-10-23 Thread Yihui Xie
list all objects first; use a loop (explicitly or not) to check
whether (1) your objects are functions (2) functions are debugged

> f = function(x) x
> g = 1
> x = ls()
> debug(f)
> sapply(x[sapply(x, function(i) is.function(get(i)))], isdebugged)
   f
TRUE
> undebug(f)
> sapply(x[sapply(x, function(i) is.function(get(i)))], isdebugged)
f
FALSE

Regards,
Yihui
--
Yihui Xie 
Phone: 515-294-6609 Web: http://yihui.name
Department of Statistics, Iowa State University
3211 Snedecor Hall, Ames, IA



On Fri, Oct 23, 2009 at 12:28 PM, Andrew Yee  wrote:
> This is kind of a dumb question:  I know you can use isdebugged() to find
> out if a specific function is flagged for debugging, but is there a way to
> list all the functions that are flagged for debugging?
> Thanks,
> Andrew
>
>        [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.