Seems we ran into the problem of using significant whitespace so appending to r ended up inside the inner loop.
Here I have moved it outside.
function distance(x, y, a, b, coverage)
r = Float64[]
for (i,xv) in enumerate(x)
R = Float64[]
for (j, jv) in enumerate(a)
if coverage[j][i] == 1
push!(R, ((x[i]-a[j])^2 + (y[i]-b[j])^2)^0.5)
end
end
if length(R) > 0
push!(r, maximum(R))
end
end
return r
end