[R] debugging non-visible functions

Prof Brian Ripley ripley at stats.ox.ac.uk
Wed Oct 13 09:00:38 CEST 2004


On Wed, 13 Oct 2004, Murad Nayal wrote:

> I would like to step-through a non-visible function. but apparently I
> don't know enough about namespaces to get that to work:
> 
> > methods(predict) 
>  ... deleted lines ... 
> [27] predict.rpart*             predict.smooth.spline*    
> [31] predict.survreg.penal*    
> 
>     Non-visible functions are asterisked
> 
> 
> > debug(predict.rpart)
> Error: Object "predict.rpart" not found
> 
> 
> > getAnywhere("predict.rpart")
> A single object matching 'predict.rpart' was found
> It was found in the following places
>   registered S3 method for predict from namespace rpart
>   namespace:rpart
> with value
> 
> function (object, newdata = list(), type = c("vector", "prob", 
>     "class", "matrix"), ...) 
> {
> ... deleted code ...
> }
> <environment: namespace:rpart>
> 
> 
> > debug(predict.rpart,pos="package:rpart")
> Error: Object "predict.rpart" not found
> 
> 
> how can I 'debug' non-visible functions, like predict.rpart?

The issue here is a non-visible S3 method.  In that case, just make a 
local copy:

predict.rpart <- rpart:::predict.rpart
debug(predict.rpart)

In general (not an S3 method), you cannot do this since the local copy may 
not be called, and the only way I know is to use fixInNamespace and insert 
browser() at the top.  Even that may not always work.

Luke Tierney recommends removing the NAMESPACE file during development of 
a package if you need frequent access to debug/change its functions.

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595




More information about the R-help mailing list