[R] R debugging options

John Fox jfox at mcmaster.ca
Fri Apr 21 22:47:28 CEST 2006


Dear Spencer,

I wasn't aware of getFunctions(), though I've now taken a look at it. It's
pretty similar to listFunctions() (from my email to the list), except that
getFunctions() uses exists() rather than is.function() to test whether an
object is a function. There must be a reason for this, but I can't think
what it is, since in both cases the vector of object names shouldn't include
nonexistent objects.

Regards,
 John

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

> -----Original Message-----
> From: Spencer Graves [mailto:spencer.graves at pdf.com] 
> Sent: Friday, April 21, 2006 11:21 AM
> To: John Fox
> Cc: 'Larry Howe'; r-help at stat.math.ethz.ch; Philippe Grosjean
> Subject: Re: [R] R debugging options
> 
> 	  Regarding a function that lists functions, have you 
> considered "getFunctions" in library(svIDE)?  You need to 
> provide the argument, as 
> in "getFunctions(1)";   "getFunctions()" returns an error message.
> 
> 	  Beyond this, the "objects" function in S-Plus (at 
> least version 6.2) has a "classes" argument, which the R 
> 2.2.1 implementation does not have.  It doesn't look like it 
> would be too difficult to add such an argument to "objects" 
> in R, but I have not been in a position to volunteer to do 
> it, and without that, I didn't feel it was appropriate for me 
> to suggest it.
> 
> 	  hope this helps,
> 	  spencer graves
> 
> John Fox wrote:
> 
> > 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
> > 
> > 
> > ______________________________________________
> > 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