[R] debugging S4 methods

Duncan Murdoch murdoch at stats.uwo.ca
Thu Oct 1 13:32:09 CEST 2009


On 01/10/2009 7:02 AM, sebastian mueller wrote:
> Hi all,
> 
> Does anyone know how to debug S4 methods? In my case I want to find an
> error in the specc-function of the kernlab-package.
> As this seems to be a S4-method the normal S3 debugging can't be
> applied apparently (e.g. debug(s3function.someclass)).
> 
> So in my case
> 
>> debug(specc:kernlab)
> seems only to debug the generic-function:
> 
>> specc:kernlab
> function (x, ...)
> standardGeneric("specc")
> <environment: 0x9088080>
> 
> which doesn't help me. Does anyone know how to debug the real-code?

You can insert a call to browser() if you want to modify the source.  If 
you'd rather not do that, you can use trace() to set a breakpoint in it.
The new setBreakpoint() function in R 2.10.0 will also work, if you 
install the package from source with the R_KEEP_PKG_SOURCE=yes 
environment variable set.  It allows you to set a breakpoint at a 
particular line number in the source code.

Duncan Murdoch




More information about the R-help mailing list