ropensci / slopes

Package to calculate slopes of roads, rivers and trajectories
https://docs.ropensci.org/slopes/
GNU General Public License v3.0
70 stars 6 forks source link

Possible bug in line_segment function #49

Closed fulliautomatix-bike closed 1 year ago

fulliautomatix-bike commented 1 year ago

Hi, I tried to use line_segment just now by segment length and got an error Error in Ops.units(n_segments, 1) : both operands of the expression should be "units" objects. It worked as expected if I run the same code but passing the function n_segments.

sf %>% line_segment(segment_length = set_units(20, 'm'))

I think the problem is that from_to_sequence = seq(from = 0, to = 1, length.out = n_segments + 1) doesn't work if the n_segments argument has a unit (even if the unit is [1] as in this case).

I made a local copy of the function and could make it work by making the following change: old: n_segments <- round(l_length/segment_length) new: n_segments <- as.numeric(round(l_length/segment_length))

Happy to provide more code or a regex if needed.

fulliautomatix-bike commented 1 year ago

Sorry, wrong package...