From maechler@stat.math.ethz.ch  Tue Apr  9 08:07:48 2002
From: maechler@stat.math.ethz.ch (maechler@stat.math.ethz.ch)
Date: Tue, 9 Apr 2002 09:07:48 +0200 (MET DST)
Subject: [Rd] match.arg confusion (PR#921)
Message-ID: <200204090707.JAA25096@pubhealth.ku.dk>

>>>>> "PD" == p dalgaard <p.dalgaard@biostat.ku.dk> writes:

    PD> [sys.function fails sometimes (sorry, our mail system
    PD> decide to throw away the original mail)]

    PD> Yes, I bumped into something similar recently. The
    PD> problem is that we only actually store the call in the
    PD> context structure, not the function, so sys.function has
    PD> to grab the call, take the 1st element, and reevaluate
    PD> it in the parent frame. It is quite easy to think up
    PD> examples where a second evaluation does not give the
    PD> same value as the first.

    PD> Your particular case is of a slightly different natur
    PD> and should be easily fixable by replacing findVar in
    PD> R_sysfunction by findVar1 and looking specifically for
    PD> objects of mode "function", but the basic problem
    PD> persists. I don't think I want to risk fixing this (and
    PD> maybe unfixing something else) for 1.2.3 tomorrow
    PD> though.

and Peter *did* implement the ``stop gap'' fix above for 1.5.0,
but the proper fix (for the more general problem) is still to be
done.

Martin

    JonR> From: J.C.Rougier@durham.ac.uk
    JonR> Date: Wed, 25 Apr 2001 13:23:09 +0200 (MET DST)
     ...

    JonR> This one may not strictly be a bug, and it was
    JonR> certainly my fault, but it took me a while to track it
    JonR> down and it is rather strange:
(it *is* bug)

     funOne <- function(x) { funTwo <- 1:10 ; funTwo(x) }

     funTwo <- function(v) 2*v

     funOne(5) # answer is 10 as expected

     # now a different definition for funTwo with a match.arg

     funTwo <- function(v, foo=c("small", "large")) { 
	       foo <- match.arg(foo); print(foo); 2*v }

     funOne(5) # answer is 10, but foo is NULL

    JonR> What happens is that in funOne I mask funTwo with a
    JonR> vector, but that doesn't matter as the call to funTwo
    JonR> specifies mode="function" (or something similar).  But
    JonR> what happens when funTwo includes a match.arg?  In
    JonR> this case match.arg fails, and the reason it fails is
    JonR> that sys.function(sys.parent()) in match.arg evaluates
    JonR> to 1:10.  If there is a bug here it is the failure of
    JonR> sys.function to grab a function, with the result that
    JonR> formal.args in match.fun is NULL.


-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel 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-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._


[Rd] match.arg confusion (PR#921)
maechler@stat.math.ethz.ch