I've been trying for 3 days to find out where the problem came from but I am a beginner in R working on the re-use of interesting scripts for my work like functions of EAA presentations. I create a new R file.
#### Calculating distances on observed point patterns ####
## creation of an lpp object
observed_lpp1 <- spatstat.linnet::lpp(
X = spatstat.geom::as.ppp(X = pp1 %>% dplyr::select(geometry)),
L = maptools::as.linnet.SpatialLines(X = as(network, "Spatial"))
)
observed_lpp2 <- spatstat.linnet::lpp(
X = spatstat.geom::as.ppp(X = pp2 %>% dplyr::select(geometry)),
L = maptools::as.linnet.SpatialLines(X = as(network, "Spatial"))
)
## calculating shortest paths for observed data
matrix_observed_dist_pi_p <- spatstat.linnet::crossdist.lpp(X = observed_lpp1, Y = observed_lpp2)
observed_dist <- matrix_observed_dist_pi_p %>%
tibble::as_tibble() %>%
tibble::rowid_to_column(var = "pp1") %>%
tidyr::pivot_longer(cols = -pp1, names_to = "pp2", values_to = "dist_pi_p") %>%
dplyr::filter(!is.na(dist_pi_p)) %>%
dplyr::mutate(pp2 = stringr::str_replace_all(string = pp2, pattern = "V", replacement = ""))
I received an error message at the line
matrix_observed_dist_pi_p <- spatstat.linnet::crossdist.lpp(X = observed_lpp1, Y = observed_lpp2)
Error in order(Yseg0, tY) : argument 2 is not a vector In addition: Warning message: In as.data.frame.hyperframe(x$data[, chosen, drop = FALSE]) : 1 variable discarded in conversion to data frame
I am currently working with R.4.2 because I needed to use maptools::as.linnet.SpatialLines.
I tried to get my observed_lpp2 as a data frame and there was no data (empty lpp)
I found the solution but still don't really understand. The problem came from observed_lpp2 code lines, i replaced by observed_lpp1 code lines and changing the variable lpp and it worked.
I let the post here in case someone faces the same issue but otherwise it can be deleted by the administrators as necessary!
Have a g'day!