Error in stopifnot(): In argument: Build.nn = nn_function(st_c(st_coid(Build_net)), st_c(HighRiseB), 3). Caused by error in **nn_function()`: ! could not find function "nn_function" Backtrace: 1. Build_net %>% ... 7. dplyr:::mutate.data.frame(...) 8. dplyr:::mutate_cols(.data, dplyr_quosures(...), by) 10. dplyr:::mutate_col(dots[[i]], data, mask, new_columns) 11. mask$eval_all_mutate(quo) 12. dplyr (local) eval()
[image] Show Traceback
Error in stopifnot(!inherits(x, "sf"), !missing(sf_column_name), !missing(agr)) : Caused by error in nn_function(): ! could not find function "nn_function"
I want to measure the average distance from each fishnet grid cell centroid (my destination layer:Distance from) to its k nearest vacant neighbors (my another point feature layer as target: Distance to)
The code block below does this using the nn_function - a custom function created for this purpose
suggests that this is the author's own function, not included in any of the libraries used. My suggestion is to open an issue on the github site or otherwise correspond with the author.
Thank you for kind answer.
After my first comment I read the text carefully for several times. Just like you, I realized that something is wrong here.
You know, the author of that tutorial passed away in 2021 unfortunately. So, I searched same projects. Then I found the same code and updated it as my project aim. Now it is working for me. This is the code where the tutorial was not:
nn_function <- function(measureFrom, measureTo, k) {
nn <- get.knnx(measureTo, measureFrom, k)$nn.dist
output <-
as.data.frame(nn) %>%
rownames_to_column(var = "thisPoint") %>%
gather(points, point_distance, V1:ncol(.)) %>%
arrange(as.numeric(thisPoint)) %>%
group_by(thisPoint) %>%
summarize(pointDistance = mean(point_distance)) %>%
arrange(as.numeric(thisPoint)) %>%
dplyr::select(-thisPoint) %>%
as.data.frame()
names(output) <- c("dist.nn")
return(output)
}