Skip to content
Prev 12395 / 398502 Next

scoping problem?

Peter Dalgaard BSA <p.dalgaard at biostat.ku.dk> writes:
Hmm. Digging a little deeper got me to the following code in do_eval
(eval.c) 

    case INTSXP:
    case REALSXP:
        nback = asInteger(env);
        if (nback==NA_INTEGER)
            errorcall(call,"invalid environment");
        if (nback > 0 )
            nback -= framedepth(R_GlobalContext);
        nback = -nback;
        PROTECT(env = R_sysframe(nback,R_GlobalContext));
        break;

This indicates that the interpretation of an integer argument to eval
is the number of frames to go back if it is *positive*. This is the
opposite of what sys.call/sys.frame does, and besides, R_sysframe does
the positive/negative conversion itself. Apparently, this code has
been sitting there "forever"... 

I think it ought to be just

    case INTSXP:
    case REALSXP:
        nback = asInteger(env);
        if (nback==NA_INTEGER)
            errorcall(call,"invalid environment");
        PROTECT(env = R_sysframe(nback,R_GlobalContext));
        break;

(possibly with a change of variable name for "nback").