From maechler@stat.math.ethz.ch  Fri Mar 22 19:42:38 2002
From: maechler@stat.math.ethz.ch (maechler@stat.math.ethz.ch)
Date: Fri, 22 Mar 2002 20:42:38 +0100 (MET)
Subject: [Rd] rare bad bug in sys.function() {or match.arg()} (PR#1409)
Message-ID: <200203221942.UAA02846@pubhealth.ku.dk>

I found this tracing a bug when experimenting with a new sort()
function using match.arg().

It was triggered because mosaicplot.default(.) has an argument
called `sort' and calls itself the sort() function  in which I
was using match.arg()...

Here is (input for) a small clean example :

####  bad  match.arg() // sys.function() bug :
####  MM, 22.3.2002

callme <- function(a = 1, mm = c("Abc", "Bde")){
    mm <- match.arg(mm)
    cat("mm = "); str(mm)
    invisible()
}


## These are as desired
callme()
callme(mm="B")

mycaller <- function(x = 1, callme = pi) {
    callme(x)
}

mycaller()
##-> mm = NULL

## but should give "Abc !!

-------

Explanation :

 In match.arg(), there's
     formal.args <- formals(sys.function(sys.parent()))
 and you can check that  sys.function(sys.parent())
 gives the number pi instead of the the callme function !! :

debug(match.arg)
mycaller()
.....

Martin Maechler <maechler@stat.math.ethz.ch>	http://stat.ethz.ch/~maechler/
Seminar fuer Statistik, ETH-Zentrum  LEO C16	Leonhardstr. 27
ETH (Federal Inst. Technology)	8092 Zurich	SWITZERLAND
phone: x-41-1-632-3408		fax: ...-1228			<><

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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] rare bad bug in sys.function() {or match.arg()} (PR#1409)
maechler@stat.math.ethz.ch