From roger at ysidro.econ.uiuc.edu  Wed Mar 26 04:52:38 2003
From: roger at ysidro.econ.uiuc.edu (Roger Koenker)
Date: Wed Mar 26 11:47:37 2003
Subject: [Rd] Rprof/UseMethod
Message-ID: <Pine.SOL.4.30.0303260437560.2088-100000@ysidro.econ.uiuc.edu>

I'm having difficulty with Rprof.  I have a documentation example test.qss that
runs fine without profiling, but under Rprof,

> Rprof()
> source("test.qss")
Error in standardGeneric("model.matrix") :
        UseMethod used in an inappropriate fashion

Luke wrote about a similar circumstance last summer:


#   From: Luke Tierney (luke@stat.umn.edu)
#   Date: Fri Jul 19 2002 - 16:03:17 EDT
#
    #   * In reply to: Bartz, Kevin: "[R] Rprof and setMethod conflict?"
#
#   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.
#
I tried this,  on my solaris "R version 1.7.0, 2003-02-05" but got complaints
about the use of env from make.  So I quickly retreated.  Any thoughts on this?


url:	www.econ.uiuc.edu	Roger Koenker		Dept. of Economics UCL,
email	rkoenker@uiuc.edu	Department of Economics Drayton House,
vox: 	217-333-4558		University of Illinois	30 Gorden St,
fax:   	217-244-6678		Champaign, IL 61820	London,WC1H 0AX, UK
							vox:	020-7679-5838


[Rd] Rprof/UseMethod
Roger Koenker