-
Notifications
You must be signed in to change notification settings - Fork 61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Option to use +
in req_url_query()
#432
Comments
Can you show the code you're using for httr? |
Sure. See below. I also found this StackOverflow discussion on the matter: https://stackoverflow.com/questions/1634271/url-encoding-the-space-character-or-20 So, maybe there could be a parameter library(dplyr)
library(stringr)
library(httr)
x <- tibble(place = "135 Pilkington Avenue",
city = "Birmingham",
zip = NA,
state = NA,
country = "UK")
req <-
paste0('https://nominatim.openstreetmap.org/search?q=',
str_replace_all(
paste0(x$place, ", ",
x$city, ", ",
if_else(is.na(x$zip), "", paste0(x$zip, ", ")),
if_else(is.na(x$state), "", paste0(x$state, ", ")),
x$country),
"\\s", "+"),
'&format=jsonv2&limit=1')
get_nominatim <-
function(request) {
r <- GET(request)
if (r$headers$`content-length` > 2) {
r %>%
content() %>%
unlist() %>%
matrix(nrow = length(.), byrow = T, dimnames = list(names(.))) %>%
t() %>%
as_tibble()
} else tibble()
}
get_nominatim(req)
#> # A tibble: 1 × 17
#> place_id licence osm_type osm_id lat lon category type place_rank
#> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr>
#> 1 241320786 Data © OpenSt… way 90394… 52.5… -1.8… building resi… 30
#> # ℹ 8 more variables: importance <chr>, addresstype <chr>, name <chr>,
#> # display_name <chr>, boundingbox1 <chr>, boundingbox2 <chr>,
#> # boundingbox3 <chr>, boundingbox4 <chr> Created on 2024-01-31 with reprex v2.1.0 Session infosessionInfo()
#> R version 4.3.2 (2023-10-31 ucrt)
#> Platform: x86_64-w64-mingw32/x64 (64-bit)
#> Running under: Windows 10 x64 (build 19044)
#>
#> Matrix products: default
#>
#>
#> locale:
#> [1] LC_COLLATE=English_Canada.utf8 LC_CTYPE=English_Canada.utf8
#> [3] LC_MONETARY=English_Canada.utf8 LC_NUMERIC=C
#> [5] LC_TIME=English_Canada.utf8
#>
#>
#> attached base packages:
#> [1] stats graphics grDevices utils datasets methods base
#>
#> other attached packages:
#> [1] httr_1.4.7 stringr_1.5.1 dplyr_1.1.4
#>
#> loaded via a namespace (and not attached):
#> [1] vctrs_0.6.5 cli_3.6.2 knitr_1.45 rlang_1.1.3
#> [5] xfun_0.41 stringi_1.8.3 generics_0.1.3 jsonlite_1.8.8
#> [9] glue_1.7.0 htmltools_0.5.7 fansi_1.0.6 rmarkdown_2.25
#> [13] evaluate_0.23 tibble_3.2.1 fastmap_1.1.1 yaml_2.3.8
#> [17] lifecycle_1.0.4 compiler_4.3.2 fs_1.6.3 pkgconfig_2.0.3
#> [21] rstudioapi_0.15.0 digest_0.6.34 R6_2.5.1 reprex_2.1.0
#> [25] tidyselect_1.2.0 utf8_1.2.4 curl_5.2.0 pillar_1.9.0
#> [29] magrittr_2.0.3 tools_4.3.2 withr_3.0.0 |
Thanks for the link. My interpretation is different, as I think using |
This is bringing back memories of r-lib/httr#335. |
Option would be appreciated! Thanks! |
req_url_query
+
in req_url_query()
For the Nominatim API[1] I need to submit my request using plus signs (+) instead of %20 (spaces). I looked at all parameters of
req_url_query()
, but couldn't find how to tweak this. Is this not yet implemented?By the way, no rush, I have used the
httr
package in the meantime...[1] Sample API call: https://nominatim.openstreetmap.org/search?q=135+pilkington+avenue,+birmingham&format=xml&polygon_kml=1&addressdetails=1
Thanks,
Tim
The text was updated successfully, but these errors were encountered: