4

I've recently started using the fantastic alphahull R package, which works beautifully most of the time but occasionally I am getting the following error when running the areaahull() function:

Error in row:rownew : NA/NaN argument

For most of my data the function works as expected, but with some data and for certain values of alpha, the above fatal error occurs. It does not seem to depend on the complexity of the data, sometimes the error occurs with a few dozen data points, while it will run fine with a dataset of a few thousand points.

The code is very straightforward, simply by changing the value of alpha for a given dataset I can generate the error.

library(alphahull)

lonlat <- read.csv("areaahull_error.csv")

alpha <- 0.2

alphahull <- ahull(lonlat, alpha = alpha)
areaahull(alphahull)

I'd be interested to know if anyone else has seen this error and if there's anything to be done about it, other than trying to catch it, or tweak alpha to avoid it when it occurs.

3

I have contacted the author of the alphahull package who is working on a solution to this problem, but was able to suggest that a slight perturbation of the data points prior to executing the areaahull() function can avoid the error. Apparently the error arises when a series of points on the hull are in a line, or very nearly in a line, and so moving these points slightly can allow the function to run smoothly.

Obviously, it is not ideal to alter data, even slightly, but I can verify that in some cases a very small change to the coordinate data is a workaround. The code below reads the original data and incorporates a random tweak:

lonlat <- read.csv("areaahull_error.csv") + matrix(rnorm(length(lonlat), sd=10^-4), nc=2)

The parameter sd might need to be changed depending on your data. I have found this approach to work in most, but not all, of my problem cases. Varying the value of alpha slightly can also help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.