diff --git a/DESCRIPTION b/DESCRIPTION index 345b2f9..04c4c81 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -27,7 +27,6 @@ Depends: R (>= 3.4.0) Imports: sfheaders, methods, - nngeo, vctrs Suggests: sf, @@ -35,7 +34,8 @@ Suggests: rmarkdown, tinytest, covr, - lwgeom + lwgeom, + nngeo RoxygenNote: 7.3.2 VignetteBuilder: knitr Roxygen: list(markdown = TRUE) diff --git a/R/points_to_od.R b/R/points_to_od.R index 566d546..55b2499 100644 --- a/R/points_to_od.R +++ b/R/points_to_od.R @@ -43,8 +43,10 @@ #' (l2_oneway = od_oneway(l2)) #' sf::st_length(l2) #' # With max_dist: -#' (l3 = points_to_odl(p, max_dist = 10000)) -#' sf::st_length(l3) +#' if (require(nngeo)) { +#' (l3 = points_to_odl(p, max_dist = 10000)) +#' sf::st_length(l3) +#' } points_to_od = function(p, pd = NULL, interzone_only = FALSE, ids_only = FALSE, max_dist = Inf, max_dest = Inf) { # to work with other classes at some point, possibly, it's a generic: @@ -81,6 +83,10 @@ points_to_od.sf = function(p, pd = NULL, interzone_only = FALSE, ids_only = FALS # Use nngeo implementation if max_dist or max_dest is provided if(max_dist < Inf || max_dest < Inf) { + # Fail gracefully if nngeo is not available: + if(!requireNamespace("nngeo", quietly = TRUE)) { + stop("nngeo must be installed for max_dist and max_dest arguments") + } if(max_dest > nrow(pd)){ max_dest = nrow(pd) } diff --git a/man/points_to_od.Rd b/man/points_to_od.Rd index 78fba73..bee7de6 100644 --- a/man/points_to_od.Rd +++ b/man/points_to_od.Rd @@ -72,6 +72,8 @@ l2$v = 1 (l2_oneway = od_oneway(l2)) sf::st_length(l2) # With max_dist: -(l3 = points_to_odl(p, max_dist = 10000)) -sf::st_length(l3) +if (require(nngeo)) { + (l3 = points_to_odl(p, max_dist = 10000)) + sf::st_length(l3) +} }