Incompatible datatype error with OpenCage query
jonathancallahan opened this issue · comments
I encountered this while reverse geocoding 1000 locations. The call to dplyr::bind_rows()
within reverse_geocode()
failed because components.road_reference
wasn't forced to <character> type.
> locationTbl <- table_addOpenCageInfo(
+ locationTbl,
+ rep .... [TRUNCATED]
Error: Can't combine `..1$components.road_reference` <character> and `..578$components.road_reference` <integer>.
Run `rlang::last_error()` to see where the error occurred.
> rlang::last_error()
<error/vctrs_error_incompatible_type>
Can't combine `..1$components.road_reference` <character> and `..578$components.road_reference` <integer>.
Backtrace:
1. base::source(...)
5. MazamaLocationUtils::table_addOpenCageInfo(...) ~/Projects/MazamaScience/known-locations/AirNow/addOpenCageInfo.R:25:0
6. tidygeocoder::reverse_geocode(...) /Users/jonathancallahan/Projects/MazamaScience/MazamaLocationUtils/R/table_addOpenCageInfo.R:102:2
9. dplyr::bind_rows(list_coords)
10. vctrs::vec_rbind(!!!dots, .names_to = .id)
12. vctrs::vec_default_ptype2(...)
13. vctrs::stop_incompatible_type(...)
14. vctrs:::stop_incompatible(...)
15. vctrs:::stop_vctrs(...)
Run `rlang::last_trace()` to see the full context.
Hi @jonathancallahan do you have a small reproducible example you could post? https://reprex.tidyverse.org/
Is components.road_reference
a nested column that can be both numeric or character?
Here is a small example:
openCageTbl <-
tidygeocoder::reverse_geocode(
.tbl = dplyr::tibble(
lat = c(47.185800, 48.762699),
long = c(-101.428100, -122.440201)
),
lat = "lat",
long = "long",
full_results = TRUE,
method = "opencage"
)
...
Error: Can't combine `..1$components.road_reference` <character> and `..2$components.road_reference` <integer>.
Hi, Ed from OpenCage here.
Just to chime in, the road_reference
value (and road_reference_intl
) we return is always a string, not a number. The format of road references varies from country to country, and by type of road. Some are a mix of numbers and characters, some also include symbols like I-95
, and many are just digits like 3356
, but in our JSON response it is always a string. Our docs should make that more clear, will get that improved today.
When I run your example I don't get an error and the components.road_reference
column comes in as character. I'm guessing this may have to do with what package versions we are using. You could try updating your httr, jsonlite, and dplyr packages to see if that fixes the issue.
Here are the package versions I'm using for reference. (output from devtools::session_info()
):
─ Session info ──────────────────────────────────────────────────────────────────────────────────────────────
setting value
version R version 4.1.0 (2021-05-18)
os Ubuntu 21.10
system x86_64, linux-gnu
ui RStudio
language (EN)
collate en_US.UTF-8
ctype en_US.UTF-8
tz America/New_York
date 2022-01-21
─ Packages ──────────────────────────────────────────────────────────────────────────────────────────────────
package * version date lib source
assertthat 0.2.1 2019-03-21 [1] CRAN (R 4.1.0)
base64enc 0.1-3 2015-07-28 [1] CRAN (R 4.1.0)
cachem 1.0.6 2021-08-19 [1] CRAN (R 4.1.0)
callr 3.7.0 2021-04-20 [1] CRAN (R 4.1.0)
cli 3.0.1 2021-07-17 [1] CRAN (R 4.1.0)
crayon 1.4.1 2021-02-08 [1] CRAN (R 4.1.0)
curl 4.3.2 2021-06-23 [1] CRAN (R 4.1.0)
DBI 1.1.1 2021-01-15 [1] CRAN (R 4.1.0)
desc 1.3.0 2021-03-05 [1] CRAN (R 4.1.0)
devtools 2.4.2 2021-06-07 [1] CRAN (R 4.1.0)
digest 0.6.28 2021-09-23 [1] CRAN (R 4.1.0)
dplyr 1.0.7 2021-06-18 [1] CRAN (R 4.1.0)
ellipsis 0.3.2 2021-04-29 [1] CRAN (R 4.1.0)
fansi 0.5.0 2021-05-25 [1] CRAN (R 4.1.0)
fastmap 1.1.0 2021-01-25 [1] CRAN (R 4.1.0)
fs 1.5.0 2020-07-31 [1] CRAN (R 4.1.0)
generics 0.1.0 2020-10-31 [1] CRAN (R 4.1.0)
glue 1.4.2 2020-08-27 [1] CRAN (R 4.1.0)
hms 1.1.1 2021-09-26 [1] CRAN (R 4.1.0)
htmltools 0.5.2 2021-08-25 [1] CRAN (R 4.1.0)
httr 1.4.2 2020-07-20 [1] CRAN (R 4.1.0)
jsonlite 1.7.2 2020-12-09 [1] CRAN (R 4.1.0)
knitr 1.34 2021-09-09 [1] CRAN (R 4.1.0)
lifecycle 1.0.1 2021-09-24 [1] CRAN (R 4.1.0)
magrittr 2.0.1 2020-11-17 [1] CRAN (R 4.1.0)
memoise 2.0.0 2021-01-26 [1] CRAN (R 4.1.0)
pillar 1.6.3 2021-09-26 [1] CRAN (R 4.1.0)
pkgbuild 1.2.0 2020-12-15 [1] CRAN (R 4.1.0)
pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 4.1.0)
pkgload 1.2.2 2021-09-11 [1] CRAN (R 4.1.0)
prettyunits 1.1.1 2020-01-24 [1] CRAN (R 4.1.0)
processx 3.5.2 2021-04-30 [1] CRAN (R 4.1.0)
progress 1.2.2 2019-05-16 [1] CRAN (R 4.1.0)
ps 1.6.0 2021-02-28 [1] CRAN (R 4.1.0)
purrr 0.3.4 2020-04-17 [1] CRAN (R 4.1.0)
R6 2.5.1 2021-08-19 [1] CRAN (R 4.1.0)
remotes 2.4.0 2021-06-02 [1] CRAN (R 4.1.0)
repr 1.1.3 2021-01-21 [1] CRAN (R 4.1.0)
rlang 0.4.11 2021-04-30 [1] CRAN (R 4.1.0)
rprojroot 2.0.2 2020-11-15 [1] CRAN (R 4.1.0)
rstudioapi 0.13 2020-11-12 [1] CRAN (R 4.1.0)
sessioninfo 1.1.1 2018-11-05 [1] CRAN (R 4.1.0)
skimr 2.1.3 2021-03-07 [1] CRAN (R 4.1.0)
stringi 1.7.4 2021-08-25 [1] CRAN (R 4.1.0)
stringr 1.4.0 2019-02-10 [1] CRAN (R 4.1.0)
testthat 3.0.4 2021-07-01 [1] CRAN (R 4.1.0)
tibble 3.1.5 2021-09-30 [1] CRAN (R 4.1.0)
tidygeocoder * 1.0.5 2022-01-21 [1] local
tidyr 1.1.3 2021-03-03 [1] CRAN (R 4.1.0)
tidyselect 1.1.1 2021-04-30 [1] CRAN (R 4.1.0)
usethis 2.0.1 2021-02-10 [1] CRAN (R 4.1.0)
utf8 1.2.2 2021-07-24 [1] CRAN (R 4.1.0)
vctrs 0.3.8 2021-04-29 [1] CRAN (R 4.1.0)
withr 2.4.2 2021-04-18 [1] CRAN (R 4.1.0)
xfun 0.26 2021-09-14 [1] CRAN (R 4.1.0)
Excellent news!
Upgrading from jsonlite 1.7.2 -> 1.7.3 fixed the problem.
You should probably include that dependency in the DESCRIPTION
file.
Thanks for looking into this.