[R] "inahull? from package alphahull not working when used with lapply

Bart Kastermans kasterma at kasterma.net
Mon Oct 27 20:09:43 CET 2014


On 27/10/14 19:42, Camilo Mora wrote:
> Hi Bart,
> 
> Even after putting the variables in the apply function, the results come not right:
> 
> library (alphahull)
> DT=data.frame(x=c(0.25,0.25,0.75,0.75),y=c(0.25,0.75,0.75,0.25))
> Hull <- ahull(DT, alpha = 0.5)
> 
> TEST<- data.frame(x=c(0.25,0.5),y=c(0.5,0.5))
> plot(Hull)
> points(TEST)
> 
> InHul2D <- function(Val1, Val2, Hull) inahull(Hull, p = c(Val1, Val2))
> 
> IN <- apply(TEST, 1, function(x,y) InHul2D("x","y",Hull))
> 
> 

Try with this version of your function:

InHul2D <- function(Val1, Val2, Hull) {
    stopifnot(is.numeric(Val1),
              is.numeric(Val2))
    inahull(Hull, p = c(Val1, Val2))
}

And answer the question; why would you put quotes around x and y in
InHul2D call in apply?  Once you remove the quotes, and get the error
"Error: argument "y" is missing, with no default" that I mentioned in my
last email, look at my last email to find out why.

I'll be happy to help you further with this, but then you have to
explain the output you get from using my version of InHul2D (before you
remove the quotes), and why my last email didn't solve the problem after
you removed the quotes.

Check ?stopifnot, and ?is.numeric

Best,
Bart



More information about the R-help mailing list