[R] list of functions flagged with debug() or trace()
Philippe Grosjean
phgrosje at ulb.ac.be
Thu Oct 11 16:25:22 CEST 2001
>You probably didn't get an answer because the answer is no, there is
>no easy way,
>--
>+--------------------------------------------------------------------------
-+
>| Robert Gentleman phone : (617) 632-5250
|
>| Associate Professor fax: (617) 632-2444
|
>| Department of Biostatistics office: M1B28
>| Harvard School of Public Health email: rgentlem at jimmy.dfci.harvard.edu
|
>+--------------------------------------------------------------------------
-+
Thank you. I would like to program it, but I feel it is not easy, because
debug() or trace() is not an attribute of the function, at least available
through attr()... My approach would be to maintain a list of functions set
with debug() or trace(). Does anybody have a better idea?
Here is a first draft:
Debug <- function(FUN) {
if (length(objects(envir=.GlobalEnv, all.names=TRUE,
pattern=".debug.functions")) != 0)
.debug.functions <- get(".debug.functions", envir=.GlobalEnv) else
.debug.functions <- NULL
assign(".debug.functions", unique(c(.debug.functions,
deparse(substitute(FUN)))), env= .GlobalEnv)
debug(FUN)
}
Undebug <- function(FUN) {
if (length(objects(envir=.GlobalEnv, all.names=TRUE,
pattern=".debug.functions")) != 0)
.debug.functions <- get(".debug.functions", envir=.GlobalEnv) else
.debug.functions <- NULL
pos <- which(.debug.functions == deparse(substitute(FUN)))
if (length(pos) > 0)
assign(".debug.functions", .debug.functions[-pos], env= .GlobalEnv)
undebug(FUN)
}
Trace <- function(FUN) {
if (length(objects(envir=.GlobalEnv, all.names=TRUE,
pattern=".trace.functions")) != 0)
.debug.functions <- get(".trace.functions", envir=.GlobalEnv) else
.debug.functions <- NULL
assign(".trace.functions", unique(c(.debug.functions,
deparse(substitute(FUN)))), env= .GlobalEnv)
trace(FUN)
}
Untrace <- function(FUN) {
if (length(objects(envir=.GlobalEnv, all.names=TRUE,
pattern=".trace.functions")) != 0)
.debug.functions <- get(".trace.functions", envir=.GlobalEnv) else
.debug.functions <- NULL
pos <- which(.debug.functions == deparse(substitute(FUN)))
if (length(pos) > 0)
assign(".trace.functions", .debug.functions[-pos], env= .GlobalEnv)
undebug(FUN)
}
Of course, I should better mask debug/undebug and trace/untrace instead of
using Debug/Undebug Trace/Untrace, but then, how do I call the original
debug/undebug, trace/untrace primitives in the body of my function?
Thanks for help,
Philippe Grosjean
...........]<(({?<...............<?}))><...............................
) ) ) ) ) __ __
( ( ( ( ( |__) | _
) ) ) ) ) | hilippe |__)rosjean
( ( ( ( ( Marine Biol. Lab., ULB, Belgium
) ) ) ) ) __
( ( ( ( ( |\ /| |__)
) ) ) ) ) | \/ |ariculture & |__)iostatistics
( ( ( ( (
) ) ) ) ) e-mail: phgrosje at ulb.ac.be or phgrosjean at sciviews.org
( ( ( ( ( SciViews project coordinator (http://www.sciviews.org)
) ) ) ) ) tel: 00-32-2-650.29.70 (lab), 00-32-2-673.31.33 (home)
( ( ( ( (
) ) ) ) ) "I'm 100% confident that p is between 0 and 1"
( ( ( ( ( L. Gonick & W. Smith (1993)
) ) ) ) )
.......................................................................
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list