Alternative location in geocode
Showing 1 of 5 files from the diff.
R/geocode.R
changed.
Other files ignored by Codecov
NEWS.md
has changed.
tests/testthat/test-geocode.R
has changed.
DESCRIPTION
has changed.
man/geocode.Rd
has changed.
@@ -6,6 +6,7 @@
Loading
6 | 6 | #' \href{https://developer.here.com/documentation/geocoding-search-api/dev_guide/topics/endpoint-geocode-brief.html}{HERE Geocoder API: Geocode} |
|
7 | 7 | #' |
|
8 | 8 | #' @param address character, addresses to geocode. |
|
9 | + | #' @param alternatives boolean, return also alternative results (\code{default = FALSE})? |
|
9 | 10 | #' @param sf boolean, return an \code{sf} object (\code{default = TRUE}) or a |
|
10 | 11 | #' \code{data.frame}? |
|
11 | 12 | #' @param url_only boolean, only return the generated URLs (\code{default = |
@@ -33,7 +34,7 @@
Loading
33 | 34 | #' set_key("<YOUR API KEY>") |
|
34 | 35 | #' |
|
35 | 36 | #' locs <- geocode(address = poi$city, url_only = TRUE) |
|
36 | - | geocode <- function(address, sf = TRUE, url_only = FALSE, addresses) { |
|
37 | + | geocode <- function(address, alternatives = FALSE, sf = TRUE, url_only = FALSE, addresses) { |
|
37 | 38 | ||
38 | 39 | if (!missing("addresses")) { |
|
39 | 40 | warning("'addresses' is deprecated, use 'address' instead.") |
@@ -42,6 +43,7 @@
Loading
42 | 43 | ||
43 | 44 | # Input checks |
|
44 | 45 | .check_addresses(address) |
|
46 | + | .check_boolean(alternatives) |
|
45 | 47 | .check_boolean(sf) |
|
46 | 48 | .check_boolean(url_only) |
|
47 | 49 |
@@ -67,7 +69,7 @@
Loading
67 | 69 | if (length(data) == 0) return(NULL) |
|
68 | 70 | ||
69 | 71 | # Extract information |
|
70 | - | geocoded <- .extract_geocoded(data, address) |
|
72 | + | geocoded <- .extract_geocoded(data, address, alternatives) |
|
71 | 73 | ||
72 | 74 | # Create sf object |
|
73 | 75 | if (nrow(geocoded) > 0) { |
@@ -95,9 +97,10 @@
Loading
95 | 97 | } |
|
96 | 98 | } |
|
97 | 99 | ||
98 | - | .extract_geocoded <- function(data, address) { |
|
100 | + | .extract_geocoded <- function(data, address, alternatives) { |
|
99 | 101 | template <- data.table::data.table( |
|
100 | 102 | id = numeric(), |
|
103 | + | rank = numeric(), |
|
101 | 104 | address = character(), |
|
102 | 105 | type = character(), |
|
103 | 106 | street = character(), |
@@ -127,6 +130,7 @@
Loading
127 | 130 | } |
|
128 | 131 | result <- data.table::data.table( |
|
129 | 132 | id = ids[count], |
|
133 | + | rank = seq_len(nrow(df$items)), |
|
130 | 134 | address = df$items$address$label, |
|
131 | 135 | type = df$items$resultType, |
|
132 | 136 | street = df$items$address$street, |
@@ -142,7 +146,11 @@
Loading
142 | 146 | lng_position = df$items$position$lng, |
|
143 | 147 | lat_position = df$items$position$lat |
|
144 | 148 | ) |
|
145 | - | result[1, ] |
|
149 | + | if (alternatives) { |
|
150 | + | return(result) |
|
151 | + | } else { |
|
152 | + | return(result[1, ]) |
|
153 | + | } |
|
146 | 154 | }) |
|
147 | 155 | ), fill = TRUE |
|
148 | 156 | ) |
Files | Coverage |
---|---|
R | 92.80% |
Project Totals (16 files) | 92.80% |
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file.
The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files.
The size and color of each slice is representing the number of statements and the coverage, respectively.