[R] Rprof and setMethod conflict?

Bartz, Kevin Kevin.Bartz at FMR.COM
Fri Jul 19 20:37:55 CEST 2002


I noticed this oddity about R profiling and setMethod.

First, I "test out" Rprof.

> require(methods)
Loading required package: methods 
[1] TRUE
> 
> Rprof("test.out")
> data.frame("a")
  X.a.
1    a
> Rprof(NULL)

So far, so good. Next, I define myClass.

> setClass("myClass", representation(mySlot = "numeric"))
[1] "myClass"
> setMethod("as.data.frame", signature(x = "myClass"),
+           function(x, row.names, optional) { "as.data.frame for myClass"
})
Creating a new generic function for "as.data.frame" on 
element 1 of the search path 
[1] "as.data.frame"

Again, everything is fine. I've expanded as.data.frame to accept objects of
class myClass. Now, let's try the standard data.frame("a") again:

> data.frame("a")
  X.a.
1    a

Still, no problems. But after I start R profiling, problems arise:

> Rprof("test2.out")
> data.frame("a")
Error in standardGeneric("as.data.frame") : 
	UseMethod used in an inappropriate fashion

It seems that I can no longer use the standard method for as.data.frame in
an R profiling sequence once I've defined a new method for it. However, I
CAN use the standard as.data.frame method when I'm NOT R profiling.

Is this the intended behavior? And if so, is there any way I can R profile
code that defines a new class with such methods?

Thanks,

Kevin

> R.version
         _                   
platform sparc-sun-solaris2.6
arch     sparc               
os       solaris2.6          
system   sparc, solaris2.6   
status                       
major    1                   
minor    5.1                 
year     2002                
month    06                  
day      17                  
language R                   
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list