Skip to content

Commit

Permalink
Merge pull request #134 from munterfinger/release/v0.7.1
Browse files Browse the repository at this point in the history
Release/v0.7.1
  • Loading branch information
munterfi authored Jul 21, 2021
2 parents 65655ab + 12f21d7 commit f08ba28
Show file tree
Hide file tree
Showing 14 changed files with 60 additions and 30 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: hereR
Type: Package
Title: 'sf'-Based Interface to the 'HERE' REST APIs
Version: 0.7.0
Version: 0.7.1
Authors@R: c(
person("Merlin", "Unterfinger", role = c("aut", "cre"), email = "[email protected]", comment = c(ORCID = "0000-0003-2020-2366")),
person("Daniel", "Possenriede", role = "ctb", comment = c(ORCID = "0000-0002-6738-9845")))
Expand Down
8 changes: 7 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# version 0.7.1

* Add parameter to allow filtering transport modes in `connection()` (closes [#130](https://github.com/munterfinger/hereR/issues/130)).
* Bugfix: Swapped the origin and destination IDs in `route_matrix()`. Removed query optimization because switching the IDs results in reversed route information (closes [#129](https://github.com/munterfinger/hereR/issues/129)).
* Update outdated URLs in package documentation.

# version 0.7.0

* Enable `optimize` parameter to chose from "balanced", "quality" and "performance" in `isoline()` (closes [#119](https://github.com/munterfinger/hereR/issues/119)).
Expand Down Expand Up @@ -73,7 +79,7 @@

* Defunct the deprecated `traffic()` function, which has been replaced by the functions `flow()` and `incident()`.
* Recreated package test data, api mocks and examples with **sf** 0.9-0 (see [#36](https://github.com/munterfinger/hereR/issues/36)).
* Increased the dependency on the **sf** package to version 0.9-0 due to a different CRS handling (for more information about the changes in **sf**, see [here](https://www.r-spatial.org/r/2020/03/17/wkt.html)). **Note: Older versions of the sf package are no longer supported.**
* Increased the dependency on the **sf** package to version 0.9-0 due to a different CRS handling (for more information about the changes in **sf**, see [here](https://r-spatial.org/r/2020/03/17/wkt.html)). **Note: Older versions of the sf package are no longer supported.**
* Temporarily deactivated maps with multiple layers until the **mapview** issue [#271](https://github.com/r-spatial/mapview/issues/271) is fixed.

# version 0.3.1
Expand Down
25 changes: 25 additions & 0 deletions R/checks.R
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,31 @@
if (!transport_mode %in% modes) {
stop(.stop_print_transport_modes(mode = transport_mode, modes = modes, request = request))
}
} else if (request == "connection") {
if (!is.null(transport_mode)) {
modes_enable <- c(
"highSpeedTrain",
"intercityTrain",
"interRegionalTrain",
"regionalTrain",
"cityTrain",
"bus",
"ferry",
"subway",
"lightRail",
"privateBus",
"inclined",
"aerial",
"busRapid",
"monorail",
"flight",
"walk"
)
modes_disable <- paste0("-", modes_enable)
if (!xor(all(transport_mode %in% modes_enable), all(transport_mode %in% modes_disable))) {
stop("Invaid value(s) for 'transport_mode'.")
}
}
}
}

Expand Down
14 changes: 13 additions & 1 deletion R/connection.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#' @param arrival boolean, calculate connections for arrival at the defined time (\code{default = FALSE})?
#' @param results numeric, maximum number of suggested public transport routes (Valid range: 1 and 6).
#' @param transfers numeric, maximum number of transfers allowed per route (Valid range: -1 and 6, whereby the \code{default = -1} allows for unlimited transfers).
#' @param transport_mode character, enable or disable (\code{"-"} prefix) transport modes. Note: Do not enable and disable modes at the same time (\code{default = NULL}).
#' @param summary boolean, return a summary of the public transport connections instead of the sections of the routes (\code{default = FALSE})?
#' @param url_only boolean, only return the generated URLs (\code{default = FALSE})?
#'
Expand All @@ -40,7 +41,8 @@
#' )
connection <- function(origin, destination, datetime = Sys.time(),
arrival = FALSE, results = 3, transfers = -1,
summary = FALSE, url_only = FALSE) {
transport_mode = NULL, summary = FALSE,
url_only = FALSE) {
# Checks
.check_points(origin)
.check_points(destination)
Expand All @@ -49,6 +51,7 @@ connection <- function(origin, destination, datetime = Sys.time(),
.check_numeric_range(transfers, -1, 6)
.check_datetime(datetime)
.check_boolean(arrival)
.check_transport_mode(transport_mode, request = "connection")
.check_boolean(summary)
.check_boolean(url_only)

Expand Down Expand Up @@ -103,6 +106,15 @@ connection <- function(origin, destination, datetime = Sys.time(),
)
}

# Add transport modes
if (!is.null(transport_mode)) {
url <- paste0(
url,
"&modes=",
paste(transport_mode, collapse = ",")
)
}

# Add route attributes
url <- paste0(
url,
Expand Down
2 changes: 1 addition & 1 deletion R/isoline.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#' @param transport_mode character, set the transport mode: \code{"car"}, \code{"pedestrian"} or \code{"truck"}.
#' @param traffic boolean, use real-time traffic or prediction in routing (\code{default = TRUE})? If no traffic is selected, the \code{datetime} is set to \code{"any"} and the request is processed independently from time.
#' @param optimize, character, specifies how isoline calculation is optimized: \code{"balanced"}, \code{"quality"} or \code{"performance"} (\code{default = "balanced"}).
#' @param consumption_model character, specify the consumption model of the vehicle, see \href{https://developer.here.com/documentation/routing-api/8.16.0/dev_guide/topics/use-cases/consumption-model.html}{consumption model} for more information (\code{default = NULL} a average electric car is set).
#' @param consumption_model character, specify the consumption model of the vehicle, see \href{https://developer.here.com/documentation/routing-api/dev_guide/topics/use-cases/consumption-model.html}{consumption model} for more information (\code{default = NULL} a average electric car is set).
#' @param aggregate boolean, aggregate (with function \code{min}) and intersect the isolines from geometry type \code{POLYGON} to geometry type \code{MULTIPOLYGON} (\code{default = TRUE})?
#' @param url_only boolean, only return the generated URLs (\code{default = FALSE})?
#'
Expand Down
4 changes: 2 additions & 2 deletions R/route.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#' to obtain an estimate of the consumption.
#'
#' @references
#' \href{https://developer.here.com/documentation/routing-api/8.16.0/dev_guide/index.html}{HERE Routing API: Calculate Route}
#' \href{https://developer.here.com/documentation/routing-api/dev_guide/index.html}{HERE Routing API: Calculate Route}
#'
#' @param origin \code{sf} object, the origin locations of geometry type \code{POINT}.
#' @param destination \code{sf} object, the destination locations of geometry type \code{POINT}.
Expand All @@ -19,7 +19,7 @@
#' @param traffic boolean, use real-time traffic or prediction in routing (\code{default = TRUE})? If no traffic is selected, the \code{datetime} is set to \code{"any"} and the request is processed independently from time.
#' @param avoid_area, \code{sf} object, area (only bounding box is taken) to avoid in routes (\code{default = NULL}).
#' @param avoid_feature character, transport network features to avoid, e.g. \code{"tollRoad"} or \code{"ferry"} (\code{default = NULL}).
#' @param consumption_model character, specify the consumption model of the vehicle, see \href{https://developer.here.com/documentation/routing-api/8.16.0/dev_guide/topics/use-cases/consumption-model.html}{consumption model} for more information (\code{default = NULL} a average electric car is set).
#' @param consumption_model character, specify the consumption model of the vehicle, see \href{https://developer.here.com/documentation/routing-api/dev_guide/topics/use-cases/consumption-model.html}{consumption model} for more information (\code{default = NULL} a average electric car is set).
#' @param url_only boolean, only return the generated URLs (\code{default = FALSE})?
#'
#' @return
Expand Down
21 changes: 2 additions & 19 deletions R/route_matrix.R
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,6 @@ route_matrix <- function(origin, destination = origin, datetime = Sys.time(),
# Setup request headers
request_headers <- .create_request_headers()

# Switch coordinates to use max request size of 15x100
if (nrow(orig_coords) > nrow(dest_coords)) {
switch <- TRUE
orig_coords_tmp <- orig_coords
orig_coords <- dest_coords
dest_coords <- orig_coords_tmp
} else {
switch <- FALSE
}

# Create URLs for batches, store original ids and format coordinates
batch_size_orig <- 15
batch_size_dest <- 100
Expand Down Expand Up @@ -147,13 +137,6 @@ route_matrix <- function(origin, destination = origin, datetime = Sys.time(),
)]
}

# Switch back indices
if (switch) {
tmp <- route_mat$orig_id
route_mat$orig_id <- route_mat$dest_id
route_mat$dest_id <- tmp
}

# Reorder
route_mat <- route_mat[order(
route_mat$orig_id,
Expand Down Expand Up @@ -226,8 +209,8 @@ route_matrix <- function(origin, destination = origin, datetime = Sys.time(),
# Matrix
routes <- data.table::data.table(
data.table::CJ(
dest_id = dest_idx[[count]][1:df$matrix$numDestinations] + 1,
orig_id = orig_idx[[count]][1:df$matrix$numOrigins] + 1
orig_id = orig_idx[[count]][1:df$matrix$numOrigins] + 1,
dest_id = dest_idx[[count]][1:df$matrix$numDestinations] + 1
),
request_id = ids[count],
departure = NA,
Expand Down
Binary file modified R/sysdata.rda
Binary file not shown.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ weather(poi, product = "alerts")

* [Developer Terms and Conditions](https://developer.here.com/terms-and-conditions)
* [Geocoding & Search API](https://developer.here.com/documentation/geocoding-search-api/dev_guide/index.html)
* [Routing API](https://developer.here.com/documentation/routing-api/8.16.0/dev_guide/index.html)
* [Routing API](https://developer.here.com/documentation/routing-api/dev_guide/index.html)
* [Matrix Routing API](https://developer.here.com/documentation/matrix-routing-api/8.2.0/dev_guide/index.html)
* [Isoline Routing API](https://developer.here.com/documentation/isoline-routing-api/8.4.0/dev_guide/index.html)
* [Traffic API](https://developer.here.com/documentation/traffic/dev_guide/topics/incident-data.html)
Expand Down
3 changes: 3 additions & 0 deletions man/connection.Rd

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

2 changes: 1 addition & 1 deletion man/isoline.Rd

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

4 changes: 2 additions & 2 deletions man/route.Rd

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

1 change: 1 addition & 0 deletions tests/testthat/test-connection.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ test_that("connection works", {
expect_error(connection(origin = poi, destination = poi, transfers = "not_numeric"))
expect_error(connection(origin = poi, destination = poi, transfers = -10))
expect_error(connection(origin = poi, destination = poi, arrival = "not_a_bool"))
expect_error(connection(origin = poi, destination = poi, transport_mode = c("highSpeedTrain", "-highSpeedTrain")))
expect_error(connection(origin = poi, destination = poi, summary = "not_a_bool"))
expect_error(connection(origin = poi, destination = poi, url_only = "not_a_bool"), "'url_only' must be a 'boolean' value.")

Expand Down
2 changes: 1 addition & 1 deletion vignettes/routing.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,6 @@ if (requireNamespace("mapview", quietly = TRUE)) {

## API Reference

* [Routing](https://developer.here.com/documentation/routing-api/8.16.0/dev_guide/index.html)
* [Routing](https://developer.here.com/documentation/routing-api/dev_guide/index.html)
* [Matrix Routing](https://developer.here.com/documentation/matrix-routing-api/8.2.0/dev_guide/index.html)
* [Isoline Routing](https://developer.here.com/documentation/isoline-routing-api/8.4.0/dev_guide/index.html)

0 comments on commit f08ba28

Please sign in to comment.