Skip to content
Prev 1926 / 63424 Next

tabulate causes segmentation fault (PR#156)

On Sun, 4 Apr 1999, Bill Venables wrote:

            
I have put a change in at the C level _and_ altered the help page to
document what tabulate does and what its arguments are. I think the 
defensive programming should be at the C level, for users can call the 
entry point.

The code is now much cleaner (I think):

tabulate <- function(bin, nbins = max(1,bin))
{
    if(!is.numeric(bin) && !is.factor(bin))
	stop("tabulate: bin must be numeric or a factor")
    .C("tabulate",
       as.integer(bin),
       as.integer(length(bin)),
       as.integer(nbins),
       ans = integer(nbins))$ans
}

As tabulate() silently ignored negative integers, I thought it could
silently ignore ones beyond nbins too, especially as I have documented
this.

I reckon the answer for
[1] 0

is wrong (I would have had a zero-length vector) but have left it for
compatibility.
Um. although not previously documented, tabulate is used with factors (as
in S).