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

tidyr error with oc_forward_df #167

Open
lsong07 opened this issue Feb 16, 2025 · 2 comments
Open

tidyr error with oc_forward_df #167

lsong07 opened this issue Feb 16, 2025 · 2 comments

Comments

@lsong07
Copy link

lsong07 commented Feb 16, 2025

I just tried only geocoding the first 5000 records of my dataframe in R and get this error, seeming like to be caused with tidyr when oc_forward_df automatically tries to clean the API responses:

result <- opencage::oc_forward_df(batch, placename = full_address)
Retrieving results from OpenCage [|] 100% ETA: 0s
Error in list_unchop():
! Can't combine x[[1]]$oc_building and x[[1280]]$oc_building .
Run rlang::last_trace() to see where the error occurred.
rlang::last_trace()
<error/vctrs_error_ptype2>
Error in list_unchop():
! Can't combine x[[1]]$oc_building and x[[1280]]$oc_building .


Backtrace:

  1. ├─opencage::oc_forward_df(batch, placename = full_address)
  2. └─opencage:::oc_forward_df.data.frame(batch, placename = full_address)
  3. ├─tidyr::unnest(results_nest, .data$op, names_repair = "unique")
  4. └─tidyr:::unnest.data.frame(results_nest, .data$op, names_repair = "unique")
  5. └─tidyr::unchop(...)
    
  6.   └─tidyr:::df_unchop(...)
    
  7.     └─vctrs::list_unchop(col, ptype = col_ptype)
    

Run rlang::last_trace(drop = FALSE) to see 9 hidden frames. > rlang::last_trace(drop = FALSE)
<error/vctrs_error_ptype2>
Error in list_unchop():
! Can't combine x[[1]]$oc_building and x[[1280]]$oc_building .

Backtrace:

  1. ├─opencage::oc_forward_df(batch, placename = full_address)
  2. ├─opencage:::oc_forward_df.data.frame(batch, placename = full_address)
  3. │ ├─tidyr::unnest(results_nest, .data$op, names_repair = "unique")
  4. │ └─tidyr:::unnest.data.frame(results_nest, .data$op, names_repair = "unique")
  5. │ └─tidyr::unchop(...)
  6. │ └─tidyr:::df_unchop(...)
  7. │ └─vctrs::list_unchop(col, ptype = col_ptype)
  8. └─vctrs (local) ()
  9. └─vctrs::vec_default_ptype2(...)
  10. ├─base::withRestarts(...)
    
  11. │ └─base (local) withOneRestart(expr, restarts[[1L]])
    
  12. │   └─base (local) doWithOneRestart(return(expr), restart)
    
  13. └─vctrs::stop_incompatible_type(...)
    
  14.   └─vctrs:::stop_incompatible(...)
    
  15.     └─vctrs:::stop_vctrs(...)
    
  16.       └─rlang::abort(message, class = c(class, "vctrs_error"), ..., call = call)
    

-->

Session information

R version 4.4.1 (2024-06-14 ucrt)
Platform: x86_64-w64-mingw32/x64
Running under: Windows 11 x64 (build 22631)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.utf8 LC_CTYPE=English_United States.utf8 LC_MONETARY=English_United States.utf8 LC_NUMERIC=C LC_TIME=English_United States.utf8

time zone: America/Los_Angeles
tzcode source: internal

attached base packages:
[1] stats graphics grDevices utils datasets methods base

other attached packages:
[1] furrr_0.3.1 future_1.34.0 ggmap_4.0.0 ggplot2_3.5.1 opencage_0.2.2 purrr_1.0.2 dplyr_1.1.4 httr_1.4.7 tidygeocoder_1.0.5

loaded via a namespace (and not attached):
[1] utf8_1.2.4 generics_0.1.3 tidyr_1.3.1 bitops_1.0-9 jpeg_0.1-10 stringi_1.8.4 httpcode_0.3.0 hms_1.1.3 listenv_0.9.1 digest_0.6.37 magrittr_2.0.3 grid_4.4.1 fastmap_1.2.0 jsonlite_1.8.9 plyr_1.8.9
[16] progress_1.2.3 crul_1.5.0 urltools_1.7.3 fansi_1.0.6 scales_1.3.0 codetools_0.2-20 cli_3.6.3 crayon_1.5.3 rlang_1.1.4 triebeard_0.4.1 parallelly_1.38.0 munsell_0.5.1 withr_3.0.1 cachem_1.1.0 tools_4.4.1
[31] parallel_4.4.1 memoise_2.0.1 colorspace_2.1-1 ratelimitr_0.4.1 globals_0.16.3 curl_6.0.0 assertthat_0.2.1 vctrs_0.6.5 R6_2.5.1 png_0.1-8 lifecycle_1.0.4 stringr_1.5.1 pkgconfig_2.0.3 pillar_1.9.0 gtable_0.3.5
[46] glue_1.8.0 Rcpp_1.0.13 tibble_3.2.1 tidyselect_1.2.1 compiler_4.4.1 prettyunits_1.2.0

@freyfogle
Copy link
Contributor

HI, Ed from OpenCage here.

I know nothing about R, but is your code assuming there will always be a building value?
That is not the case.

@dpprdan
Copy link
Member

dpprdan commented Feb 18, 2025

@lsong07 We've seen errors like this before when the OpenCage API returns results for the same field (here building) with different types (usually some string for some results and a number for others). So this could be the case here as well.

Could you please provide the full_address of the rows that failed (apparently rows 1 and 1280), so we can check?

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

3 participants