[Rd] Managed to confuse match.arg (PR#921)

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

This one may not strictly be a bug, and it was certainly my
fault, but it took me a while to track it down and it is rather

funOne <- function(x)
  funTwo <- 1:10

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)

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

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

Cheers, Jonathan.

--please do not edit the information below--

 platform = sparc-sun-solaris2.7
 arch = sparc
 os = solaris2.7
 system = sparc, solaris2.7
 status = 
 major = 1
 minor = 2.1
 year = 2001
 month = 01
 day = 15
 language = R

Search Path:
 .GlobalEnv, Autoloads, package:base

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