[Rd] rare bad bug in sys.function() {or match.arg()} (PR#1409)

Peter Dalgaard BSA p.dalgaard@biostat.ku.dk
22 Mar 2002 23:39:10 +0100


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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._