[R] tracing SV3 methods

William Dunlap wdunlap at tibco.com
Wed Mar 11 20:30:08 CET 2009


I would like to put traces on the methods for an SV3 generic
and trace() doesn't seem to work.  E.g.,

  > median(1:10)
  [1] 5.5
  > trace(median.default)
  > median(1:10) # expect "Tracing median.default ..."
  [1] 5.5

I can tell that median.default is getting called, since
a trace on sort() shows it in the traceback:

  > trace(sort,Quote(cat(deparse(sys.calls()),sep="\n")))
  Tracing function "sort" in package "base"
  [1] "sort"
  > median(1:10)
  Tracing sort(x, partial = half + 0L:1L) on entry 
  list(median(1:10), median.default(1:10), sort(x, 
      partial = half + 0L:1L), .doTrace(cat(deparse(
      sys.calls()), sep = "\n"), "on entry"),
      eval.parent(exprObj), eval(expr,p), eval(expr,
      envir, enclos))
  [1] 5.5

Is there a recommended way to do this?  (I'd like to put a
trace on all methods of a SV3 generic to see which get called
in various situations.)

This was in R 2.8.1 on Windows but I see the same results
in several versions of R.

Bill Dunlap
TIBCO Software Inc - Spotfire Division
wdunlap tibco.com 




More information about the R-help mailing list