This sounds like a bug in the usemethod code. Profiling adds an extra
evaluation context around builtins and that can confuse things that
don't take this into account. I unfortunately don't have time to
track this properly now, but on a quick glance it looks like changing
cptr = R_GlobalContext;
if ( !(cptr->callflag & CTXT_FUNCTION) || cptr->cloenv != env)
error("UseMethod used in an inappropriate fashion");
it two places in objects.c to
cptr = R_GlobalContext;
if (cptr->callflag == CTXT_BUILTIN)
cptr = cptr->nextcontext;
if ( !(cptr->callflag & CTXT_FUNCTION) || cptr->cloenv != env)
error("UseMethod used in an inappropriate fashion");
might fix this.
luke
On Fri, Jul 19, 2002 at 02:37:55PM -0400, Bartz, Kevin
wrote:> 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
>
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
--
Luke Tierney
University of Minnesota Phone: 612-625-7843
School of Statistics Fax: 612-624-8868
313 Ford Hall, 224 Church St. S.E. email: luke at stat.umn.edu
Minneapolis, MN 55455 USA WWW: http://www.stat.umn.edu
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._