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)

3

There are 3 best solutions below

1
Anne L On

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!

0
Adrian Baddeley On

Tip: When you get an error message in R, immediately type traceback(). This will tell you where the error was detected, and will give many clues.

This error is occurring because the internal format of the object observed_lpp2 is corrupted somehow.

I can't diagnose the cause further, without an example where the problem occurs. So please provide a minimal working example, that is, a simple data example and R script which causes the problem to occur.

0
Anne L On

Thank you for your answer. I investigated and it came from the linear network (lpp2). I cleaned

Note: I used explode lines from QGIS processings and it was not working whereas the number of segments was identical.

Most of the "inf" distances were corrected then.