Skip to content
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

reverse_geo fails if input is multiple identical pairs of coordinates #129

Closed
long39ng opened this issue Aug 20, 2021 · 1 comment
Closed

Comments

@long39ng
Copy link

reverse_geo throws an error if I supply the same pair of coordinates multiple times and the input has only one unique pair of coordinates.

If I supply the same pair of coordinates multiple times, but this is not the only unique pair, reverse geocoding works fine. Here's a minimal example:

suppressPackageStartupMessages(library(dplyr))
library(tidygeocoder)

df <- tibble(lat = 0, long = 0)

df |> 
  reverse_geocode(lat = lat, long = long)
#> # A tibble: 1 × 3
#>     lat  long address  
#>   <dbl> <dbl> <chr>    
#> 1     0     0 Soul Buoy
  
df[rep(1, 5), ] |> 
  reverse_geocode(lat = lat, long = long)
#> Error in vapply(elements, encode, character(1)): values must be length 1,
#>  but FUN(X[[2]]) result is length 5

df[rep(1, 5), ] |> 
  add_row(lat = 10, long = 10) |> 
  reverse_geocode(lat = lat, long = long)
#> # A tibble: 6 × 3
#>     lat  long address                    
#>   <dbl> <dbl> <chr>                      
#> 1     0     0 Soul Buoy                  
#> 2     0     0 Soul Buoy                  
#> 3     0     0 Soul Buoy                  
#> 4     0     0 Soul Buoy                  
#> 5     0     0 Soul Buoy                  
#> 6    10    10 Mun-Munsal, Bauchi, Nigeria

Created on 2021-08-21 by the reprex package (v2.0.1)

(geo, however, works fine if the same location string is supplied multiple times.)

jessecambon added a commit that referenced this issue Aug 21, 2021
@jessecambon
Copy link
Owner

Thanks for reporting this. The issue was that in the reverse_geo() function the set of (duplicated) coordinates was being put into the query instead of the single unique coordinate.

You can install the bug fix from the main GitHub branch for now:

devtools::install_github("jessecambon/tidygeocoder")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants