jmlondon / pathroutr

R package for routing tracks around barrier polygons
https://jmlondon.github.io/pathroutr/
16 stars 2 forks source link

Incorrect number of dimensions error with prt_trim() #27

Open Miguelbirostris opened 1 year ago

Miguelbirostris commented 1 year ago

Hi! I am working around a satelite tracking dataset in which several of the last points en up over and (an animal moving closely to the coastline). I jave tried to apply prt_trim() as suggested by pathroutr, but I am etting this error.

class(track_pts) [1] "sfc_MULTIPOINT" "sfc"
class(ns_polygon) [1] "sf" "data.frame" track_pts_fix<-prt_trim(track_pts,ns_polygon) Error in [.default(trkpts, head_start:tail_end, ) : Incorrect number of dimensions

Any workaround?

mfutia commented 1 year ago

I was able to resolve this by removing a comma in the prt_trim() function using the trace function.

trace(track_pts, edit = T)

Then on line 22 of the trace (42 of the function file) remove the comma within brackets

trkpts <- trkpts[head_start:tail_end,] #Comma at the end of this line 
jdpye commented 1 year ago

There may be times where that trailing comma is appropriate, but i think posting a sample of the source datasets here could help us tease out a version of this function that handles those cases but also your cases in a sensible way.

jmlondon commented 1 year ago

@Miguelbirostris thank you for posting this Issue. And, thank you to @mfutia and @jdpye for your comments.

I'm fairly certain that 'comma' is a typo ... but, need some time to double check with some sample data. So, if you can share a small dataset as part of a regex, that would be helpful as an additional check.

I suspect there are still some older/naive 'less than best' coding practices sprinkled throughout pathroutr with respect to some of the dplyr/purrr functions underneath. This could also be one of those situations.