maechler@stat.math.ethz.ch
2002-Mar-22 19:42 UTC
[Rd] rare bad bug in sys.function() {or match.arg()} (PR#1409)
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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Peter Dalgaard BSA
2002-Mar-22 22:39 UTC
[Rd] rare bad bug in sys.function() {or match.arg()} (PR#1409)
maechler@stat.math.ethz.ch writes:> 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() > .....This looks suspiciously like the same issue as PR#921. Did someone have plans to change the context stack handling so that we could have a "real" sys.function()? To quote my own followup to PR#921: "The problem is that we only actually store the call in the context structure, not the function, so sys.function has to grab the call, take the 1st element, and reevaluate it in the parent frame." -- O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard@biostat.ku.dk) FAX: (+45) 35327907 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
maechler@stat.math.ethz.ch
2002-Mar-23 18:01 UTC
[Rd] rare bad bug in sys.function() {or match.arg()} (PR#1409)
>>>>> "PD" == Peter Dalgaard BSA <p.dalgaard@biostat.ku.dk> writes:PD> maechler@stat.math.ethz.ch writes: >> 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() ..... PD> This looks suspiciously like the same issue as PD> PR#921. Did someone have plans to change the context PD> stack handling so that we could have a "real" PD> sys.function()? To quote my own followup to PR#921: PD> "The problem is that we only actually store the call in PD> the context structure, not the function, so sys.function PD> has to grab the call, take the 1st element, and PD> reevaluate it in the parent frame." hmm, bad news. but couldn't it try to do the equivalent of get(name, mode = "function") instead of simply get(name) ? [I think this *must* be fixed, at least we'd have to program around it in match.arg()] Martin -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._