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 | #' \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 = |
25 | 26 | #' set_key("<YOUR API KEY>") |
|
26 | 27 | #' |
|
27 | 28 | #' locs <- geocode(address = poi$city, url_only = TRUE) |
|
28 | - | geocode <- function(address, sf = TRUE, url_only = FALSE, addresses) { |
|
29 | + | geocode <- function(address, alternatives = FALSE, sf = TRUE, url_only = FALSE, addresses) { |
|
29 | 30 | ||
30 | 31 | if (!missing("addresses")) { |
|
31 | 32 | warning("'addresses' is deprecated, use 'address' instead.") |
34 | 35 | ||
35 | 36 | # Input checks |
|
36 | 37 | .check_addresses(address) |
|
38 | + | .check_boolean(alternatives) |
|
37 | 39 | .check_boolean(sf) |
|
38 | 40 | .check_boolean(url_only) |
|
39 | 41 |
59 | 61 | if (length(data) == 0) return(NULL) |
|
60 | 62 | ||
61 | 63 | # Extract information |
|
62 | - | geocoded <- .extract_geocoded(data, address) |
|
64 | + | geocoded <- .extract_geocoded(data, address, alternatives) |
|
63 | 65 | ||
64 | 66 | # Create sf object |
|
65 | 67 | if (nrow(geocoded) > 0) { |
87 | 89 | } |
|
88 | 90 | } |
|
89 | 91 | ||
90 | - | .extract_geocoded <- function(data, address) { |
|
92 | + | .extract_geocoded <- function(data, address, alternatives) { |
|
91 | 93 | template <- data.table::data.table( |
|
92 | 94 | id = numeric(), |
|
95 | + | rank = numeric(), |
|
93 | 96 | address = character(), |
|
94 | 97 | type = character(), |
|
95 | 98 | street = character(), |
119 | 122 | } |
|
120 | 123 | result <- data.table::data.table( |
|
121 | 124 | id = ids[count], |
|
125 | + | rank = seq_len(nrow(df$items)), |
|
122 | 126 | address = df$items$address$label, |
|
123 | 127 | type = df$items$resultType, |
|
124 | 128 | street = df$items$address$street, |
134 | 138 | lng_position = df$items$position$lng, |
|
135 | 139 | lat_position = df$items$position$lat |
|
136 | 140 | ) |
|
137 | - | result[1, ] |
|
141 | + | if (alternatives) { |
|
142 | + | return(result) |
|
143 | + | } else { |
|
144 | + | return(result[1, ]) |
|
145 | + | } |
|
138 | 146 | }) |
|
139 | 147 | ), fill = TRUE |
|
140 | 148 | ) |
Files | Coverage |
---|---|
R | 92.80% |
Project Totals (16 files) | 92.80% |