Skip to content

Commit 65655ab

Browse files
authored
Merge pull request #126 from munterfinger/release/v0.7.0
Release/v0.7.0
2 parents 12789dc + d0a6ff5 commit 65655ab

48 files changed

Lines changed: 400 additions & 245 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

DESCRIPTION

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: hereR
22
Type: Package
33
Title: 'sf'-Based Interface to the 'HERE' REST APIs
4-
Version: 0.6.1
4+
Version: 0.7.0
55
Authors@R: c(
66
person("Merlin", "Unterfinger", role = c("aut", "cre"), email = "info@munterfinger.ch", comment = c(ORCID = "0000-0003-2020-2366")),
77
person("Daniel", "Possenriede", role = "ctb", comment = c(ORCID = "0000-0002-6738-9845")))
@@ -19,8 +19,9 @@ Description: Interface to the 'HERE' REST APIs <https://developer.here.com/devel
1919
Locations, routes and isolines are returned as 'sf' objects.
2020
Depends: R (>= 3.3.0)
2121
Imports:
22+
crul (>= 1.1.0),
2223
curl (>= 4.3),
23-
data.table (>= 1.12.6),
24+
data.table (>= 1.13.0),
2425
flexpolyline (>= 0.2.0),
2526
jsonlite (>= 1.7.0),
2627
sf (>= 0.9-0),

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export(route_matrix)
1414
export(set_auth)
1515
export(set_key)
1616
export(set_proxy)
17+
export(set_rate_limit)
1718
export(set_verbose)
1819
export(station)
1920
export(traffic)

NEWS.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
# version 0.7.0
2+
3+
* Enable `optimize` parameter to chose from "balanced", "quality" and "performance" in `isoline()` (closes [#119](https://github.com/munterfinger/hereR/issues/119)).
4+
* Remove deprecated parameters in `route()`, `route_matrix()` and `isoline()`.
5+
* Add specific user-agent to the requests: `hereR/<version> R/<version> (<platform>)`.
6+
* Add option to deactivate rate limits `set_rate_limit(FALSE)`.
7+
* Bugfix: Add rate limits in RPS (requests per seconds) to async requests to the APIs; move dependency for requests from **curl** to **crul** package (closes [#122](https://github.com/munterfinger/hereR/issues/122)).
8+
* Bugfix: `isoline()` now handles multipart polygons (MULTIPOLYGON) if received by the API (closes [#121](https://github.com/munterfinger/hereR/issues/121)).
9+
* Add area and feature avoidance in `route()` (closes [#117](https://github.com/munterfinger/hereR/issues/117)).
10+
111
# version 0.6.1
212

313
* Use **styler** package and use `tyler::tidyverse_style()`to format the package.

R/autosuggest.R

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
autosuggest <- function(address, results = 5, url_only = FALSE) {
2222

2323
# Check addresses
24-
.check_addresses(address)
24+
.check_character(address)
2525
.check_numeric_range(results, 1, 100)
2626
.check_boolean(url_only)
2727

@@ -34,7 +34,7 @@ autosuggest <- function(address, results = 5, url_only = FALSE) {
3434
url <- paste0(
3535
url,
3636
"&q=",
37-
address
37+
curl::curl_escape(address)
3838
)
3939

4040
# Add bbox containing the world
@@ -56,8 +56,9 @@ autosuggest <- function(address, results = 5, url_only = FALSE) {
5656
}
5757

5858
# Request and get content
59-
data <- .get_content(
60-
url = url
59+
data <- .async_request(
60+
url = url,
61+
rps = 5
6162
)
6263
if (length(data) == 0) {
6364
return(NULL)

R/checks.R

Lines changed: 57 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
.check_addresses <- function(addresses) {
2-
if (!is.character(addresses)) {
1+
.check_character <- function(text) {
2+
if (!is.character(text) & !is.null(text)) {
33
stop(sprintf(
44
"'%s' must be a 'character' vector.",
5-
deparse(substitute(addresses))
5+
deparse(substitute(text))
66
))
77
}
8-
if (any(is.na(addresses))) {
8+
if (any(is.na(text))) {
99
stop(sprintf(
1010
"'%s' contains NAs.",
11-
deparse(substitute(addresses))
11+
deparse(substitute(text))
1212
))
1313
}
14-
if ("" %in% gsub(" ", "", addresses)) {
14+
if ("" %in% gsub(" ", "", text)) {
1515
stop(sprintf(
1616
"'%s' contains empty strings.",
17-
deparse(substitute(addresses))
17+
deparse(substitute(text))
1818
))
1919
}
2020
}
@@ -41,26 +41,28 @@
4141
}
4242

4343
.check_polygon <- function(polygon) {
44-
if (!"sf" %in% class(polygon)) {
45-
stop(sprintf(
46-
"'%s' must be an sf object.",
47-
deparse(substitute(polygon))
48-
))
49-
}
50-
if (any(sf::st_is_empty(polygon))) {
51-
stop(sprintf(
52-
"'%s' has empty entries in the geometry column.",
53-
deparse(substitute(polygon))
54-
))
55-
}
56-
if (!"sf" %in% class(polygon) |
57-
any(!(
58-
sf::st_geometry_type(polygon) %in% c("POLYGON", "MULTIPOLYGON")
59-
))) {
60-
stop(sprintf(
61-
"'%s' must be an sf object with geometry type 'POLYGON' or 'MULTIPOLYGON'.",
62-
deparse(substitute(polygon))
63-
))
44+
if (!is.null(polygon)) {
45+
if (!"sf" %in% class(polygon)) {
46+
stop(sprintf(
47+
"'%s' must be an sf object.",
48+
deparse(substitute(polygon))
49+
))
50+
}
51+
if (any(sf::st_is_empty(polygon))) {
52+
stop(sprintf(
53+
"'%s' has empty entries in the geometry column.",
54+
deparse(substitute(polygon))
55+
))
56+
}
57+
if (!"sf" %in% class(polygon) |
58+
any(!(
59+
sf::st_geometry_type(polygon) %in% c("POLYGON", "MULTIPOLYGON")
60+
))) {
61+
stop(sprintf(
62+
"'%s' must be an sf object with geometry type 'POLYGON' or 'MULTIPOLYGON'.",
63+
deparse(substitute(polygon))
64+
))
65+
}
6466
}
6567
}
6668

@@ -140,6 +142,19 @@
140142
}
141143
}
142144

145+
.check_optimize <- function(optimize) {
146+
optimizations <- c("balanced", "quality", "performance")
147+
if (!optimize %in% optimizations) {
148+
stop(
149+
sprintf(
150+
"Optimization method '%s' not valid, must be in ('%s').",
151+
optimize,
152+
paste(optimizations, collapse = "', '")
153+
)
154+
)
155+
}
156+
}
157+
143158
.check_range_type <- function(range_type) {
144159
range_types <- c("distance", "time", "consumption")
145160
if (!range_type %in% range_types) {
@@ -198,3 +213,18 @@
198213
))
199214
}
200215
}
216+
217+
.check_internet <- function() {
218+
access <- tryCatch(
219+
{
220+
curl::has_internet()
221+
},
222+
error = function(cond) {
223+
warning(cond)
224+
return(FALSE)
225+
}
226+
)
227+
if (!access) {
228+
stop("Connection error: Please check internet access and proxy configuration.")
229+
}
230+
}

R/connection.R

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,9 @@ connection <- function(origin, destination, datetime = Sys.time(),
115115
}
116116

117117
# Request and get content
118-
data <- .get_content(
119-
url = url
118+
data <- .async_request(
119+
url = url,
120+
rps = 10
120121
)
121122
if (length(data) == 0) {
122123
return(NULL)

R/flow.R

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,9 @@ flow <- function(aoi, min_jam_factor = 0, url_only = FALSE) {
8686
}
8787

8888
# Request and get content
89-
data <- .get_content(
90-
url = url
89+
data <- .async_request(
90+
url = url,
91+
rps = Inf
9192
)
9293
if (length(data) == 0) {
9394
return(NULL)

R/geocode.R

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
geocode <- function(address, alternatives = FALSE, sf = TRUE, url_only = FALSE) {
3737

3838
# Input checks
39-
.check_addresses(address)
39+
.check_character(address)
4040
.check_boolean(alternatives)
4141
.check_boolean(sf)
4242
.check_boolean(url_only)
@@ -50,7 +50,7 @@ geocode <- function(address, alternatives = FALSE, sf = TRUE, url_only = FALSE)
5050
url <- paste0(
5151
url,
5252
"&q=",
53-
gsub("\\|", "", address)
53+
curl::curl_escape(address)
5454
)
5555

5656
# Return urls if chosen
@@ -59,8 +59,9 @@ geocode <- function(address, alternatives = FALSE, sf = TRUE, url_only = FALSE)
5959
}
6060

6161
# Request and get content
62-
data <- .get_content(
63-
url = url
62+
data <- .async_request(
63+
url = url,
64+
rps = 5
6465
)
6566
if (length(data) == 0) {
6667
return(NULL)

R/incident.R

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,9 @@ incident <- function(aoi, from = Sys.time() - 60 * 60 * 24 * 7, url_only = FALSE
7070
}
7171

7272
# Request and get content
73-
data <- .get_content(
74-
url = url
73+
data <- .async_request(
74+
url = url,
75+
rps = Inf
7576
)
7677
if (length(data) == 0) {
7778
return(NULL)

R/intermodal_route.R

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,9 @@ intermodal_route <- function(origin, destination, datetime = Sys.time(),
101101
}
102102

103103
# Request and get content
104-
data <- .get_content(
105-
url = url
104+
data <- .async_request(
105+
url = url,
106+
rps = 5
106107
)
107108
if (length(data) == 0) {
108109
return(NULL)

0 commit comments

Comments
 (0)