wvenable@arcola.stats.adelaide.edu.au
1999-Apr-03 08:38 UTC
tabulate causes segmentation fault (PR#156)
Peter, I thought this one was noted and fixed, but I could be wrong. R : Copyright 1999, The R Development Core Team Version 0.63.3 (March 6, 1999) .... [Previously saved workspace restored] > tabulate(1:10, 5) Process R:1 segmentation fault at Sat Apr 3 17:48:34 1999 -- (The following contact details become official on 1 May 1999, but the email address works now and may be used from now on.) ----------------------------------------------------------------- Bill Venables, Statistician, CMIS Environmetrics Project. Physical address: Postal address: CSIRO Marine Laboratories, PO Box 120, 233 Middle St, Cleveland, Queensland Cleveland, Qld, 4163 AUSTRALIA AUSTRALIA Telephone: +61 7 3826 7200 Email: Bill.Venables@cmis.csiro.au Fax: +61 7 3826 7304 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
wvenable@arcola.stats.adelaide.edu.au writes:> Peter, > > I thought this one was noted and fixed, but I could be wrong. > > R : Copyright 1999, The R Development Core Team > Version 0.63.3 (March 6, 1999) > > .... > > [Previously saved workspace restored] > > > tabulate(1:10, 5) > > Process R:1 segmentation fault at Sat Apr 3 17:48:34 1999It wasn't... However, all it needs is a bit of defensive programming. But should it (a) Protest if any(bin)>nbins or (b) Quietly set bin[bin>nbins] <- 0 # or NA, no matter (one could also start the routine with bin<-bin[bin<=nbin]) I think (b) since that is consistent with the way values <= 0 are currently handled. -- O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard@biostat.ku.dk) FAX: (+45) 35327907 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
On Sun, 4 Apr 1999, Bill Venables wrote:> >>>>> "Peter" == Peter Dalgaard BSA <p.dalgaard@biostat.ku.dk> writes: > > Peter> wvenable@arcola.stats.adelaide.edu.au writes: > > >> R : Copyright 1999, The R Development Core Team Version > >> 0.63.3 (March 6, 1999) > >> > >> .... > >> > >> [Previously saved workspace restored] > >> > >> > tabulate(1:10, 5) > >> > >> Process R:1 segmentation fault at Sat Apr 3 17:48:34 1999 > > Peter> It wasn't... > > Peter> However, all it needs is a bit of defensive > Peter> programming. > > Yes, Peter, but by whom? My point was that this kind of massive > bear trap was not something that should be the users' sole > responsibility to avoid. Having a simple exception capable of > killing the session and losing all data is perhaps OK for > MicroSoft, but it should not be OK for us. I believe the flaw is > still present in the nascent 0.64, which bothers me. > > I think it should be solved at the C level since tabulate() is > one of those things that you want to be ultra-slick, but if this > is not possible right now, perhaps we will have to put up with aI 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> tabulate(numeric(0))[1] 0 is wrong (I would have had a zero-length vector) but have left it for compatibility.> stop-gap measure. For example you could change it in 0.64 to > > 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) && !all(OK <- (bin <= nbins))) > bin <- bin[OK] > n <- length(bin) > storage.mode(bin) <- "integer" > > .C("tabulate", bin, n, ans = integer(nbins))$ans > }Um. although not previously documented, tabulate is used with factors (as in S). -- Brian D. Ripley, ripley@stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272860 (secr) Oxford OX1 3TG, UK Fax: +44 1865 272595 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._