[R] how to debug (mtrace) a function defined inside a function?

MarkBravington Mark.Bravington at csiro.au
Sun Dec 5 02:44:47 CET 2010


Hi Andre

Just saw your email; I'm the author of the 'debug' package but I don't
subscribe to R-help, so it's best to email me directly with questions about
'debug' or 'mvbutils'.

The quick answer is that you can either: 

 -  mtrace( mymodel), then after it has executed the 'build <-
function()...' line, type 
mtrace( build) at the prompt

 - or you can insert the line below into your code of mymodel, so that you
won't need to step thru mymodel when it exectues. You could put an 'if'
statement based on a global variable if you want to be able to control
debugging behaviour "globally".

HTH
Mark Bravington (mark dot bravington at csiro dot au)

mymodel<-function(){
 data<-numeric(0)
 build<-function(){
   data<<-1
 }
 
  ## Add this:
  mtrace( build)

 m<-list()
 m$build<-build
 m
} 
-- 
View this message in context: http://r.789695.n4.nabble.com/how-to-debug-mtrace-a-function-defined-inside-a-function-tp3019781p3072957.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list