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

Martin Maechler Martin Maechler <maechler@stat.math.ethz.ch>
Fri, 9 May 97 15:38:33 +0200


There is a problem with  'default argument evaluation'
when I use an existing function name as argument name :

sintest <- function(x, y = 2, sin= sin(pi/4))
{
  ## Purpose: Test of   "default argument evaluation"
  ## -------- Fails for  R-0.49.  Martin Maechler, Date:  9 May 97.
  c(x=x, y=y, sin=sin)
}

## R-0.49:
R> sintest(1)
##> Error in sintest(1) : recursive default argument reference

## S-plus 3.4  (being 100% ok):
S> sintest(1)
  x y       sin 
  1 2 0.7071068
 Warning messages:
   looking for function "sin", ignored local non-function in: sintest(1)

-------------------------------------------------------
The following shows bugs, both in R and S:

sintest2 <- function(x ,y = 2)
{
  ## Purpose: Test of   "default argument evaluation"
  ## -------- Fails for  S-plus 3.4.  Martin Maechler, Date:  9 May 97.
  c(x=x, y=y, sin=sin)
}

R> sintest2(1)
[[1]]
[1] 1

[[2]]
[1] 2

[[3]]
<primitive: sin>

--------------- is almost okay, 
		the buglet being that the names have been dropped from the list.

But watch this:
S> sintest2(1)
function(x = 1, y = 2, sin.x)
sin2 = .Internal(sin(x), "do_math", T, 109)

--- returning a function 

	((now we see, why S's way of treating functions as
	  lists sometimes badly sucks)).
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
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
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-