From p.dalgaard at biostat.ku.dk  Mon Aug 16 12:01:20 2004
From: p.dalgaard at biostat.ku.dk (Peter Dalgaard)
Date: Mon Aug 16 12:05:39 2004
Subject: [Rd] bus error /segmentation fault from 'approx' (PR#7177)
In-Reply-To: <20040816093649.075AB10EA6@slim.kubism.ku.dk>
References: <20040816093649.075AB10EA6@slim.kubism.ku.dk>
Message-ID: <x28ycfh05r.fsf@biostat.ku.dk>

j.van_den_hoff@fz-rossendorf.de writes:

> follow up to ID 7166. something like
> 
> approx(c(1,2),c(NA,NA),1.5,rule=2)
> 
> crashes 1.9.1 on both systems (MacOS 10.3.5.: bus error,  SunOS 5.9:
> segmentation fault) even if xout is within given x range (as in example above)
> where rule=2 seems not be relevant anyway.

Yes, this is a silly bug in the R driver routine:


    if (nx < 2 && method == "linear")
        stop("approx requires at least two values to interpolate")
    if (any(na <- is.na(x) | is.na(y))) {
        ok <- !na
        x <- x[ok]
        y <- y[ok]
        nx <- length(x)
    }

You want to do the check after removing NAs! 

Also, we should probably have a check for (nx == 0 && method != "linear")

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


[Rd] bus error /segmentation fault from 'approx' (PR#7177)
Peter Dalgaard