Skip to content

Commit

Permalink
Allow n_segments to be > 1, fix #560
Browse files Browse the repository at this point in the history
  • Loading branch information
Robinlovelace committed May 1, 2024
1 parent dd21f41 commit dba1894
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions R/linefuns.R
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ line_midpoint <- function(l, tolerance = NULL) {
#' @export
#' @examples
#' library(sf)
#' l <- routes_fast_sf[2:4, ]
#' l <- routes_fast_sf[2:4, "ID"]
#' l_seg_multi <- line_segment(l, segment_length = 1000, use_rsgeo = FALSE)
#' l_seg_n <- line_segment(l, n_segments = 2)
#' l_seg_n <- line_segment(l, n_segments = c(1:3))
Expand Down Expand Up @@ -202,7 +202,7 @@ line_segment <- function(
use_rsgeo = NULL,
debug_mode = FALSE) {
# Defensive programming:
if (is.na(segment_length) && is.na(n_segments)) {
if (any(is.na(segment_length)) && any(is.na(n_segments))) {
rlang::abort(
"segment_length or n_segments must be set.",
call = rlang::caller_env()
Expand All @@ -219,7 +219,7 @@ line_segment.sf <- function(
debug_mode = FALSE
) {
# Get n_segments if not provided:
if (is.na(n_segments)) {
if (all(is.na(n_segments))) {
segment_lengths <- as.numeric(sf::st_length(l))
n_segments <- n_segments(segment_lengths, segment_length)
} else {
Expand Down
2 changes: 1 addition & 1 deletion man/line_segment.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit dba1894

Please sign in to comment.