[R] R debugging options

John Fox jfox at mcmaster.ca
Tue Apr 18 23:37:30 CEST 2006


Dear Larry,

I'm not aware of an existing function that lists functions, but here's a
simple solution:

listFunctions <- function(all.names=FALSE, envir=.GlobalEnv){
    # all.names=TRUE: include names beginning with "."
    # envir: environment to search
    Objects <- objects(envir, all.names=all.names)
    if (length(Objects) == 0) Objects
    else names(which(sapply(Objects, 
        function(object) is.function(eval(parse(text=object),
envir=envir)))))
    }

Getting mtrace() to use the function names returned by listFunctions() is a
bit tricky, because of the way mtrace() evaluates its arguments. You could
do something like the following:

for(f in listFunctions()) mtrace(char.fname=f)

Perhaps someone else knows of an existing or better solution.

I hope this helps,
 John

--------------------------------
John Fox
Department of Sociology
McMaster University
Hamilton, Ontario
Canada L8S 4M4
905-525-9140x23604
http://socserv.mcmaster.ca/jfox 
-------------------------------- 

> -----Original Message-----
> From: r-help-bounces at stat.math.ethz.ch 
> [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Larry Howe
> Sent: Tuesday, April 18, 2006 12:46 PM
> To: r-help at stat.math.ethz.ch
> Subject: Re: [R] R debugging options
> 
> On Monday April 17 2006 21:08, Francisco J. Zagmutt wrote:
> > RSiteSearch("debug") or RSiteSearch("debugging") will give 
> you a lot 
> > or relevant information.  I personally use library(debug) 
> extensivelly 
> > and it should do all the taks you asked about. There is a 
> nice article 
> > describing the debug lilbrary in the 2003/3 issue of R News 
> > http://cran.r-project.org/doc/Rnews/Rnews_2003-3.pdf
> >
> > Cheers
> >
> > Francisco
> 
> Wow! That is a great package. I think it does all I need.
> 
> Is there a way to turn on debugging for all loaded functions? 
> My source file contains many functions and I would prefer not 
> to have to mtrace() each one. 
> Something like
> 
> >mtrace(how_do_I_get_a_list_of_all_loaded_functions)
> 
> ?
> 
> Larry
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! 
> http://www.R-project.org/posting-guide.html




More information about the R-help mailing list