Closed ddunn801 closed 5 months ago
I can (basically) reproduce your results:
library(opencage)
addr <- "553 NE Olney Ave, 97701"
oc_forward_df(addr, limit = 10L)
#> # A tibble: 2 × 4
#> placename oc_lat oc_lng oc_formatted
#> <chr> <dbl> <dbl> <chr>
#> 1 553 NE Olney Ave, 97701 44.1 -121. 553 Northeast Olney Avenue, Bend, OR 97…
#> 2 553 NE Olney Ave, 97701 44.1 -121. Deschutes County, OR 97701, United Stat…
oc_forward_df(addr, limit = 10L, countrycode = "US")
#> # A tibble: 2 × 4
#> placename oc_lat oc_lng oc_formatted
#> <chr> <dbl> <dbl> <chr>
#> 1 553 NE Olney Ave, 97701 44.1 -121. NE Olney Ave, Bend, OR, United States o…
#> 2 553 NE Olney Ave, 97701 44.1 -121. Deschutes County, OR 97701, United Stat…
I’ve used the raw address you provided. Your toget
contains a slightly different housenumber IIUC. BTW, {opencage} does the URL-encoding for you, so you can use the “raw” address. Note that oc_forward_df()
directly returns a data.frame and not a df_list
, which is more practical for this use case IMHO.
That said, the different results come from the OpenCage API and are not caused by the {opencage} package. These are the queries sent to the OpenCage API (with OPENCAGE_KEY
replaced by an actual API key):
oc_forward(addr, limit = 10L, return = "url_only")
#> [[1]]
#> [1] "https://api.opencagedata.com/geocode/v1/json?q=553%20NE%20Olney%20Ave%2C%2097701&limit=10&no_annotations=1&roadinfo=0&no_dedupe=0&no_record=1&abbrv=0&address_only=0&add_request=0&key=OPENCAGE_KEY"
oc_forward(addr, limit = 10L, countrycode = "US", return = "url_only")
#> [[1]]
#> [1] "https://api.opencagedata.com/geocode/v1/json?q=553%20NE%20Olney%20Ave%2C%2097701&countrycode=us&limit=10&no_annotations=1&roadinfo=0&no_dedupe=0&no_record=1&abbrv=0&address_only=0&add_request=0&key=OPENCAGE_KEY"
Some points I noticed while looking into this:
Long story short: I can reproduce the results but there is nothing (sensible) I can do at the {opencage} package level to fix this. The result is a bit strange but I am not sure I would call this a bug that needs fixing at the API level. Pinging @freyfogle nevertheless.
Created on 2024-06-27 with reprex v2.1.0
Great diagnosis @dpprdan very comprehensive.
Will investigate.
But yes, adding the address to OpenStreetMap is always a great idea. Here's a guide.
Wow, this turned into quite the interesting bug, thanks so much for posting it.
One of the big challenges we have to deal with is people sending us only partially formed addresses.
Basically when countrycode
is set, we do additional country-specific logic.
Say for example someone send us 553 NE Olney Ave, 97701
because they can't be bothered to include the town name or the state, as is common in US addresses.
So we have a lot of logic to try to add missing information like that. This includes expanding common abbreviations, for example, the abbreviations of state codes.
As I'm sure you are aware NE
is the two-letter state code of the great state of Nebraska (The Cornhusker State).
That leads to all sorts of confusion.
This is now fixed and test cases added.
Both queries return the same result now, indeed:
library(opencage)
addr <- "553 NE Olney Ave, 97701"
(oc1 <- oc_forward_df(addr, limit = 10L))
#> # A tibble: 2 × 4
#> placename oc_lat oc_lng oc_formatted
#> <chr> <dbl> <dbl> <chr>
#> 1 553 NE Olney Ave, 97701 44.1 -121. 553 Northeast Olney Avenue, Bend, OR 97…
#> 2 553 NE Olney Ave, 97701 44.1 -121. Deschutes County, OR 97701, United Stat…
(oc2 <- oc_forward_df(addr, limit = 10L, countrycode = "US"))
#> # A tibble: 2 × 4
#> placename oc_lat oc_lng oc_formatted
#> <chr> <dbl> <dbl> <chr>
#> 1 553 NE Olney Ave, 97701 44.1 -121. 553 Northeast Olney Avenue, Bend, OR 97…
#> 2 553 NE Olney Ave, 97701 44.1 -121. Deschutes County, OR 97701, United Stat…
all.equal(oc1, oc2)
#> [1] TRUE
Thanks @ddunn801 for reporting!
Description & steps to reproduce
The results returned are unexpectedly different when including the country_code parameter in oc_forward, even though all results include the US country_code.
Session information