Skip to content

R-alpha: R-0.49 / S-plus: "default argument evaluation" bugs and woes

1 message · Luke Tierney

#
Martin Maechler wrote:
For better or worse, S and R allow default expressions to contain
references variables that are (or rather may be) created in the
function body, so (in R and Splus)
Error: Argument "a" is missing, with no default
[1] 2
[1] 1

More traditional lexical scoping would make the reference to x in the
default always be global, but lots of code would break. I think we're
stuck with this behavior as a corollary to the way S wants default
arguments to work.

Actually S is a bit inconsistent in its error message -- if you have a
non-function argument it gives the same message as R,
Error in g(): Recursive occurrence of default argument "x"
Dumped

Also in R's lexical scoping you probably do want the argument name to
shadow any outer definitions if you want to be able to define default
arguments that are recursive functions, e.g.
[1] 720