[Rd] rare bad bug in sys.function() {or match.arg()} (PR#1409)
maechler@stat.math.ethz.ch
maechler@stat.math.ethz.ch
Sat, 23 Mar 2002 19:01:33 +0100 (MET)
>>>>> "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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._