Re: [Rd] How to debug reference classes?

From: John Chambers <jmc_at_r-project.org>
Date: Thu, 07 Apr 2011 14:50:26 -0700

This is a good wish-list item. The natural mechanism would be a version of the standard trace() function as a reference method with the same arguments as the current trace(), minus those that make no sense. So:

    xx$trace(edit, browser)
for example, to trace execution of the reference method "edit" defined in the class of xx. The mechanism does not exist now, and will require some modifications or extensions to the existing trace() implementation.

Meanwhile, the following slightly ugly workaround seems to apply trace() to a reference method. Here, xx is the object created in the example for ReferenceClasses, with method $edit(). [Actually running the example removes the class definition, so this was done from a copy of the source code for the example.]

The steps in the workaround:

An example is below.

Of course, one could also just define xx$edit to call a regular function, say myEdit() and trace that. But the workaround doesn't require changing the existing definition.

Suggestions for a better or less ugly workaround are welcome. I'll look at fixing up a trace() method for 2.13.1

John



 > edit <- xx$edit
 > trace(edit, browser, where = xx)
Constructing traceable class "refMethodDefWithTrace" Environment of class "refMethodDef" is locked; using global environment for new class
Tracing function "edit" in package "2011-04-07 14:34:43" [1] "edit"
Warning message:
In getPackageName(whereF) :

   Created a package name, "2011-04-07 14:34:43", when none found  > rm(edit)
 > xx$edit(1,2,3)
Tracing xx$edit(1, 2, 3) on entry
Called from: eval(expr, envir, enclos)
Browse[1]> objects()
[1] "i" "j" "value"
Browse[1]> j
[1] 2
Browse[1]> j <- 3
Browse[1]>
 > xx$data

      [,1] [,2] [,3]

[1,]    1    5    3
[2,]    2    6   10
[3,]    3    7   11
[4,]    4    8   12

 > untrace("edit", where = xx)
Untracing function "edit" in package "2011-04-07 14:34:43"  > xx$edit(1,2,-1)
 > xx$data

      [,1] [,2] [,3]

[1,]    1   -1    3
[2,]    2    6   10
[3,]    3    7   11
[4,]    4    8   12

============================================

On 4/7/11 12:00 PM, A Zege wrote:
> How do you debug methods of a reference class? I've been using mtrace, which
> is excellent, but i cannot figure out how to mtrace a reference class
> method. Maybe there is some other way to debug these, for example with
> ordinary trace? for now i am only able to use options(error=recover), which
> is not giving me idea where exactly in the code i am once i am stopped on an
> error.

>

> --
> View this message in context: http://r.789695.n4.nabble.com/How-to-debug-reference-classes-tp3434269p3434269.html
> Sent from the R devel mailing list archive at Nabble.com.
>

> ______________________________________________
> R-devel@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Thu 07 Apr 2011 - 21:54:00 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 07 Apr 2011 - 22:20:42 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.

list of date sections of archive