# [Rd] approxfun(*, ties=) returning "random" result (PR#986)

**maechler@stat.math.ethz.ch
**
maechler@stat.math.ethz.ch

*Mon, 18 Jun 2001 12:35:54 +0200 (MET DST)*

Platforms : SunOS and Linux, both using gcc 2.95.[23]
R versions : 1.2.3 and "R-devel"
I came accross this when trying to debug a somewhat sub-optimal behavior of
ecdf() from package stepfun.
What happens is that approxfun(*, ties = <function>)
does not always return the same result for identical arguments.
I tried "min", "max", and "mean" all of which are mentioned on the help page.
>*From looking at both R and C code, I wonder if the bug is not even deep
*inside where .C(......) is handled, or somewhere else ``deep down''...
I could debug more myself, but given the ``immediate release'' and my
limited resources, I'll pass this on :
###---------- the following is executable; read and follow the comments
n <- length(xt <- c(.4,.4,.4,1,1.05,2,3,3,3.4, 4,4,4,4:5, 7,7))
e2 <- approxfun(xt,(1:n)/n, method = "const", yl=0, yr=1, f=0, ties=max)
e2(xt)# all "1" (well mostly...)
gcinfo(TRUE)
## Execute the following (long) line a few times...
## the non-1 solution happens often (not always!) immediately *after* GC..
for(i in 1:100) {ee <- e2(xt);if(!is.na(b <- all(ee == 1)) && b) cat(".") else cat("\n",16*ee,"\n")}
## The problem happens only when ties = <function>, not for ties = "ordered":
e1 <- approxfun(xt,(1:n)/n, method = "const", yl=0, yr=1, f=0, ties="ordered")
e1xt <- c(3,3,3:6,8,8,9,rep(13,4),14,15,15)/16
stopifnot(e1(xt) == e1xt)
## Execute the following (long) line a few times...
## -- no problem, always "........."
for(i in 1:100) {ee <- e1(xt);if(!is.na(b <- all(ee == e1xt))&& b)cat(".") else cat("\n",16*ee,"\n")}
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._