From wvenable@arcola.stats.adelaide.edu.au  Sun Apr  4 07:11:49 1999
From: wvenable@arcola.stats.adelaide.edu.au (Bill Venables)
Date: Sun, 4 Apr 1999 15:41:49 +0930 (CST)
Subject: tabulate causes segmentation fault (PR#156)
In-Reply-To: <14086.44603.723137.13426@arcola.stats.adelaide.edu.au>
References: <199904030838.KAA31481@blueberry.kubism.ku.dk>
 <x2hfqydp4f.fsf@blueberry.kubism.ku.dk>
 <14086.44603.723137.13426@arcola.stats.adelaide.edu.au>
Message-ID: <14087.677.890232.822546@arcola.stats.adelaide.edu.au>

OK, I have a few noodles around my ears...  

The fix I gave for tabulate can cause problems with factors (and
breaks truehist in the MASS library!).  Here is a further
refinement, which is now getting a little messy, I do admit, but
I'm pretty sure this covers it.  (At least truehist works...)

--(begin tabulate.R)--
tabulate <- function (bin, nbins = max(bin)) {
    if (!is.numeric(bin) && !is.factor(bin)) 
        stop("tabulate: bin must be numeric or a factor")
    nbins <- max(0, nbins)

    if (!missing(nbins)) {
      if (is.factor(bin))
        bin <- unclass(bin)
      if (!all(OK <- (bin <= nbins)))
        bin <- bin[OK]
    }

    n <- length(bin)
    storage.mode(bin) <- "integer"
    .C("tabulate", bin, n, ans = integer(nbins))$ans
}
--(end tabulate.R)--
Bill Venables.
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._


tabulate causes segmentation fault (PR#156)
Bill Venables