[Rd] interp.surface() error (PR#7745)

takahama at andrew.cmu.edu takahama at andrew.cmu.edu
Wed Mar 23 22:16:30 CET 2005


R version: 2.001
OS: Windows XP SP2

When I use the interp.surface() function, on occasion I have encountered 
the following error message:

Error in interp.surface(a, loc) : subscript out of bounds

Since it is somewhat dependent on the data set, I cannot say exactly in 
which cases these occur, but I believe I have found the problem and a 
solution for it:

The scaling calculations in the code,
    lx <- ((nx - 1) * (loc[, 1] - xa))/xr + 1
    ly <- ((ny - 1) * (loc[, 2] - ya))/yr + 1
can lead to numerical error, so in the following lines
    lx1 <- ifelse(lx == nx, nx - 1, trunc(lx))
    ly1 <- ifelse(ly == ny, ny - 1, trunc(ly))
the equality statements which are the first arguments to the IF-ELSE 
statements return false when they are supposed to be true. I believe the 
remedy is to simply avoid absolute equalities, as in the following example 
(which has worked for my problem):
    lx1 <- ifelse(abs(lx - nx) < 1e-10, nx - 1, trunc(lx))
    ly1 <- ifelse(abs(ly - ny) < 1e-10, ny - 1, trunc(ly))

I hope this is an appropriate posting for an error report. Thank you very 
much for your hard work,

Satoshi
_____
Satoshi Takahama
Dept. of Chemical Engineering
Carnegie Mellon University
Pittsburgh, PA 15213
Phone: 412-268-7570



More information about the R-devel mailing list