hist(1) results in a segmentation fault (at least on my machine) (PR#86)

Martin Maechler Martin Maechler <maechler@stat.math.ethz.ch>
Wed, 23 Dec 1998 12:59:03 +0100


I've fixed hist.default();
the case for  hist(0) and hist(-1)  also needed consideration.

Here is the patch I've committed:

cvs diff -bw -r1.2.2.1 src/library/base/R/hist.R
diff -b -w -r1.2.2.1 -r1.2.2.4
16,18c16,18
<     use.br <- !missing(breaks) && length(breaks) > 1
<     breaks <-
< 	if(use.br) sort(breaks)
---
>     use.br <- !missing(breaks) && (nB <- length(breaks)) > 1
>     if(use.br)
> 	breaks <- sort(breaks)
20,22c20,22
< 	    rx <- range(x)
< 	    pretty (rx + c(0, diff(rx)/1000),
< 		    n = if(missing(breaks)) 1 + log2(n)
---
> 	dx <- diff(rx <- range(x))
> 	nnb <-
> 	    if(missing(breaks)) 1 + log2(n)
27d26
< 		    })
28a28
> 	breaks <- pretty (rx + c(-1,1)/1000 * dx, n = nnb)
29a30,35
> 	if(nB == 1) {##	 search anew for breaks; dx is (always ?) 0.
> 	    breaks <-
> 		if(abs(breaks) > 1e-20) sort(breaks * c(.8, 1.2)) else c(-.2,.2)
> 	    nB <- length(breaks)
> 	}
>     }

As you may see, I've also changed
from a potentially asymmetric  rx + c(0, dx/1000)
to a symmetric interval	       rx + c(-1,1)/1000 * dx

Hope this okay even so it changes current behavior in some cases.

-------------

Merry Christmas to all!
I'm gone for the next few days..

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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._