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

Error due to type conflict in new version of tibble #49

Closed
jaspercooper opened this issue Oct 6, 2020 · 4 comments
Closed

Error due to type conflict in new version of tibble #49

jaspercooper opened this issue Oct 6, 2020 · 4 comments
Labels
bug Something isn't working

Comments

@jaspercooper
Copy link

hi @jessecambon — thanks for this awesome package. It solves a huge problem in my workflow!

I've encountered a hiccup that appears to be due to tibble. The following code ran fine before I updated tibble, but broke afterward:

geo(
  street = "9500 Gilman Dr.,",
  city = "San Diego",
  state = "CA",
  postalcode = "92161",
  method = "cascade"
)

The error reads:

Error: Assigned data `retry_results` must be compatible with existing data.
ℹ Error occurred for column `lat`.
✖ Can't convert from <double> to <logical> due to loss of precision.
* Locations: 1.

The error seems to be coming from here:

combi[na_indices,] <- retry_results

Tibble is not happy that the variable types are being overwritten.

If instead you change line 70 to something more explicit like combi[,c("lat","long")] <- retry_results[,c("lat","long")] everything runs just fine.

Hope this helps, thanks again for the great package!

@jessecambon jessecambon added the bug Something isn't working label Oct 7, 2020
@jessecambon
Copy link
Owner

jessecambon commented Oct 7, 2020

Thanks for reporting this, I was able to replicate the issue. It looks like this error is coming from vctrs:

https://vctrs.r-lib.org/reference/vec_cast.html

I haven't gotten a chance to dig into it yet, but the solution may be to force the lat/long coordinates to be formatted as a double in the extract_results or geo functions.

The Census geocoder is returning 'logical' format for the lat/long columns:

a <- geo(
    street = "9500 Gilman Dr.,",
    city = "San Diego",
    state = "CA",
    postalcode = "92161",
    method = "census"
)

summary(a)
#>    street              city              state            postalcode          lat            long        
#> Length:1           Length:1           Length:1           Length:1           Mode:logical   Mode:logical  
#> Class :character   Class :character   Class :character   Class :character   NA's:1         NA's:1        
#> Mode  :character   Mode  :character   Mode  :character   Mode  :character   

When using method = 'cascade', the numeric lat/long results from the 'osm' geocoder are being put into these 'logical' columns which is what causes the error.

@jaspercooper
Copy link
Author

Yeah, that sounds right. It may be as simple as fixing the variable types in the initial_results tibble. I'd check out debugonce(geo_cascade) again though --- it also appears the subsetting by na_indices around line 70 isn't quite doing what it's supposed to (presumably singling out the columns with NAs), as it's defined as a scalar on line 56.

jessecambon added a commit that referenced this issue Oct 7, 2020
@jessecambon
Copy link
Owner

jessecambon commented Oct 7, 2020

@jaspercooper I've got a bug fix for you to try out:

devtools::install_github("jessecambon/tidygeocoder", ref = 'cascade-na-fix')

I changed the the lat/long NA values from NA to as.numeric(NA) in the extract_results() and get_na_results() functions in utils.R. I haven't tested too extensively yet so let me know if you run into any issues. The na_indices variable in geo_method.R is for the row numbers for addresses that were not found by the first method tried.

@jaspercooper
Copy link
Author

Thanks, I actually found a workaround in the meantime just by writing my own "cascade" script with geocode_osm and geocode_census. Worked great, those functions are awesome and saved me a lot of time. Thanks for this great package!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants