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

From: <>
Date: Mon 16 Aug 2004 - 22:19:16 EST

>>>>> "PD" == Peter Dalgaard <> >>>>> on 16 Aug 2004 12:01:20 +0200 writes:

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

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

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

    PD> You want to do the check after removing NAs!

    PD> Also, we should probably have a check for (nx == 0 && method != "linear") yes (2 times) *and* 'method' is not a string anymore at that moment because it has been pmatch()ed.

I'm going to match.arg() it instead.
And I see there's more cleanup possible, since, xy.coords() already makes sure to return 2 equal length numeric components.

When I do this now, it breaks back compatibility since things like (PR#6809)

        approx(list(x=rep(NaN, 9), y=1:9), xout=NaN) would give an error instead of (NaN, NaN).

OTOH, the stop("....") message you cite above was obviously *intended* to be triggered for such a case. I presume we rather intend to be back compatible?

Martin mailing list Received on Mon Aug 16 22:21:59 2004

This archive was generated by hypermail 2.1.8 : Wed 03 Nov 2004 - 22:45:07 EST