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

[BUG] Regression (?) in opq_osm_id() #268

Closed
agila5 opened this issue Mar 10, 2022 · 5 comments · Fixed by #282
Closed

[BUG] Regression (?) in opq_osm_id() #268

agila5 opened this issue Mar 10, 2022 · 5 comments · Fixed by #282

Comments

@agila5
Copy link
Contributor

agila5 commented Mar 10, 2022

Hi @mpadge! I want to report a possible regression in opq_osm_id. The following example (taken from ?opq_osm_id) fails with the current CRAN version:

remotes::install_cran("osmdata", quiet = TRUE)
library(osmdata)
#> Data (c) OpenStreetMap contributors, ODbL 1.0. https://www.openstreetmap.org/copyright
id <- c (1489221200, 1489221321, 1489221491)
opq_osm_id (type = "node", id = id) %>%
  opq_string () %>%
  osmdata_sf ()
#> Error in opq_osm_id(type = "node", id = id): Only a single id may be entered.

Created on 2022-03-10 by the reprex package (v2.0.1)

Session info
sessioninfo::session_info()
#> - Session info ---------------------------------------------------------------
#>  setting  value
#>  version  R version 4.1.2 (2021-11-01)
#>  os       Windows 10 x64 (build 19042)
#>  system   x86_64, mingw32
#>  ui       RTerm
#>  language (EN)
#>  collate  English_United Kingdom.1252
#>  ctype    English_United Kingdom.1252
#>  tz       Europe/Berlin
#>  date     2022-03-10
#>  pandoc   2.16.2 @ C:/PROGRA~1/Pandoc/ (via rmarkdown)
#> 
#> - Packages -------------------------------------------------------------------
#>  package     * version date (UTC) lib source
#>  backports     1.4.1   2021-12-13 [1] CRAN (R 4.1.2)
#>  cli           3.2.0   2022-02-14 [1] CRAN (R 4.1.2)
#>  crayon        1.5.0   2022-02-14 [1] CRAN (R 4.1.2)
#>  curl          4.3.2   2021-06-23 [1] CRAN (R 4.1.1)
#>  digest        0.6.29  2021-12-01 [1] CRAN (R 4.1.2)
#>  ellipsis      0.3.2   2021-04-29 [1] CRAN (R 4.1.1)
#>  evaluate      0.14    2019-05-28 [1] CRAN (R 4.1.1)
#>  fansi         1.0.2   2022-01-14 [1] CRAN (R 4.1.2)
#>  fastmap       1.1.0   2021-01-25 [1] CRAN (R 4.1.1)
#>  fs            1.5.2   2021-12-08 [1] CRAN (R 4.1.2)
#>  generics      0.1.2   2022-01-31 [1] CRAN (R 4.1.2)
#>  glue          1.6.2   2022-02-24 [1] CRAN (R 4.1.2)
#>  highr         0.9     2021-04-16 [1] CRAN (R 4.1.1)
#>  htmltools     0.5.2   2021-08-25 [1] CRAN (R 4.1.1)
#>  httr          1.4.2   2020-07-20 [1] CRAN (R 4.1.1)
#>  jsonlite      1.8.0   2022-02-22 [1] CRAN (R 4.1.2)
#>  knitr         1.37    2021-12-16 [1] CRAN (R 4.1.2)
#>  lattice       0.20-45 2021-09-22 [2] CRAN (R 4.1.2)
#>  lifecycle     1.0.1   2021-09-24 [1] CRAN (R 4.1.1)
#>  lubridate     1.8.0   2021-10-07 [1] CRAN (R 4.1.1)
#>  magrittr      2.0.2   2022-01-26 [1] CRAN (R 4.1.2)
#>  osmdata     * 0.1.9   2022-01-26 [1] CRAN (R 4.1.2)
#>  pillar        1.7.0   2022-02-01 [1] CRAN (R 4.1.2)
#>  pkgconfig     2.0.3   2019-09-22 [1] CRAN (R 4.1.1)
#>  purrr         0.3.4   2020-04-17 [1] CRAN (R 4.1.1)
#>  R.cache       0.15.0  2021-04-30 [1] CRAN (R 4.1.1)
#>  R.methodsS3   1.8.1   2020-08-26 [1] CRAN (R 4.1.1)
#>  R.oo          1.24.0  2020-08-26 [1] CRAN (R 4.1.1)
#>  R.utils       2.11.0  2021-09-26 [1] CRAN (R 4.1.1)
#>  R6            2.5.1   2021-08-19 [1] CRAN (R 4.1.1)
#>  Rcpp          1.0.8   2022-01-13 [1] CRAN (R 4.1.2)
#>  remotes       2.4.2   2021-11-30 [1] CRAN (R 4.1.2)
#>  reprex        2.0.1   2021-08-05 [1] CRAN (R 4.1.1)
#>  rlang         1.0.2   2022-03-04 [1] CRAN (R 4.1.2)
#>  rmarkdown     2.11    2021-09-14 [1] CRAN (R 4.1.1)
#>  rstudioapi    0.13    2020-11-12 [1] CRAN (R 4.1.1)
#>  rvest         1.0.2   2021-10-16 [1] CRAN (R 4.1.1)
#>  sessioninfo   1.2.2   2021-12-06 [1] CRAN (R 4.1.2)
#>  sp            1.4-6   2021-11-14 [1] CRAN (R 4.1.2)
#>  stringi       1.7.6   2021-11-29 [1] CRAN (R 4.1.2)
#>  stringr       1.4.0   2019-02-10 [1] CRAN (R 4.1.1)
#>  styler        1.6.2   2021-09-23 [1] CRAN (R 4.1.1)
#>  tibble        3.1.6   2021-11-07 [1] CRAN (R 4.1.2)
#>  utf8          1.2.2   2021-07-24 [1] CRAN (R 4.1.1)
#>  vctrs         0.3.8   2021-04-29 [1] CRAN (R 4.1.1)
#>  withr         2.4.3   2021-11-30 [1] CRAN (R 4.1.2)
#>  xfun          0.29    2021-12-14 [1] CRAN (R 4.1.2)
#>  xml2          1.3.3   2021-11-30 [1] CRAN (R 4.1.2)
#>  yaml          2.2.2   2022-01-25 [1] CRAN (R 4.1.2)
#> 
#>  [1] C:/Users/andre/Documents/R/win-library/4.1
#>  [2] C:/Program Files/R/R-4.1.2/library
#> 
#> ------------------------------------------------------------------------------

the github version:

remotes::install_github("ropensci/osmdata", quiet = TRUE)
library(osmdata)
#> Data (c) OpenStreetMap contributors, ODbL 1.0. https://www.openstreetmap.org/copyright
id <- c (1489221200, 1489221321, 1489221491)
opq_osm_id (type = "node", id = id) %>%
  opq_string () %>%
  osmdata_sf ()
#> Error in opq_osm_id(type = "node", id = id): Only a single id may be entered.

Created on 2022-03-10 by the reprex package (v2.0.1)

Session info
sessioninfo::session_info()
#> - Session info ---------------------------------------------------------------
#>  setting  value
#>  version  R version 4.1.2 (2021-11-01)
#>  os       Windows 10 x64 (build 19042)
#>  system   x86_64, mingw32
#>  ui       RTerm
#>  language (EN)
#>  collate  English_United Kingdom.1252
#>  ctype    English_United Kingdom.1252
#>  tz       Europe/Berlin
#>  date     2022-03-10
#>  pandoc   2.16.2 @ C:/PROGRA~1/Pandoc/ (via rmarkdown)
#> 
#> - Packages -------------------------------------------------------------------
#>  package     * version   date (UTC) lib source
#>  backports     1.4.1     2021-12-13 [1] CRAN (R 4.1.2)
#>  callr         3.7.0     2021-04-20 [1] CRAN (R 4.1.1)
#>  cli           3.2.0     2022-02-14 [1] CRAN (R 4.1.2)
#>  crayon        1.5.0     2022-02-14 [1] CRAN (R 4.1.2)
#>  curl          4.3.2     2021-06-23 [1] CRAN (R 4.1.1)
#>  digest        0.6.29    2021-12-01 [1] CRAN (R 4.1.2)
#>  ellipsis      0.3.2     2021-04-29 [1] CRAN (R 4.1.1)
#>  evaluate      0.14      2019-05-28 [1] CRAN (R 4.1.1)
#>  fansi         1.0.2     2022-01-14 [1] CRAN (R 4.1.2)
#>  fastmap       1.1.0     2021-01-25 [1] CRAN (R 4.1.1)
#>  fs            1.5.2     2021-12-08 [1] CRAN (R 4.1.2)
#>  generics      0.1.2     2022-01-31 [1] CRAN (R 4.1.2)
#>  glue          1.6.2     2022-02-24 [1] CRAN (R 4.1.2)
#>  highr         0.9       2021-04-16 [1] CRAN (R 4.1.1)
#>  htmltools     0.5.2     2021-08-25 [1] CRAN (R 4.1.1)
#>  httr          1.4.2     2020-07-20 [1] CRAN (R 4.1.1)
#>  jsonlite      1.8.0     2022-02-22 [1] CRAN (R 4.1.2)
#>  knitr         1.37      2021-12-16 [1] CRAN (R 4.1.2)
#>  lattice       0.20-45   2021-09-22 [2] CRAN (R 4.1.2)
#>  lifecycle     1.0.1     2021-09-24 [1] CRAN (R 4.1.1)
#>  lubridate     1.8.0     2021-10-07 [1] CRAN (R 4.1.1)
#>  magrittr      2.0.2     2022-01-26 [1] CRAN (R 4.1.2)
#>  osmdata     * 0.1.9.001 2022-03-10 [1] Github (ropensci/osmdata@bf0d639)
#>  pillar        1.7.0     2022-02-01 [1] CRAN (R 4.1.2)
#>  pkgbuild      1.3.1     2021-12-20 [1] CRAN (R 4.1.2)
#>  pkgconfig     2.0.3     2019-09-22 [1] CRAN (R 4.1.1)
#>  prettyunits   1.1.1     2020-01-24 [1] CRAN (R 4.1.1)
#>  processx      3.5.2     2021-04-30 [1] CRAN (R 4.1.1)
#>  ps            1.6.0     2021-02-28 [1] CRAN (R 4.1.1)
#>  purrr         0.3.4     2020-04-17 [1] CRAN (R 4.1.1)
#>  R.cache       0.15.0    2021-04-30 [1] CRAN (R 4.1.1)
#>  R.methodsS3   1.8.1     2020-08-26 [1] CRAN (R 4.1.1)
#>  R.oo          1.24.0    2020-08-26 [1] CRAN (R 4.1.1)
#>  R.utils       2.11.0    2021-09-26 [1] CRAN (R 4.1.1)
#>  R6            2.5.1     2021-08-19 [1] CRAN (R 4.1.1)
#>  Rcpp          1.0.8     2022-01-13 [1] CRAN (R 4.1.2)
#>  remotes       2.4.2     2021-11-30 [1] CRAN (R 4.1.2)
#>  reprex        2.0.1     2021-08-05 [1] CRAN (R 4.1.1)
#>  rlang         1.0.2     2022-03-04 [1] CRAN (R 4.1.2)
#>  rmarkdown     2.11      2021-09-14 [1] CRAN (R 4.1.1)
#>  rprojroot     2.0.2     2020-11-15 [1] CRAN (R 4.1.1)
#>  rstudioapi    0.13      2020-11-12 [1] CRAN (R 4.1.1)
#>  rvest         1.0.2     2021-10-16 [1] CRAN (R 4.1.1)
#>  sessioninfo   1.2.2     2021-12-06 [1] CRAN (R 4.1.2)
#>  sp            1.4-6     2021-11-14 [1] CRAN (R 4.1.2)
#>  stringi       1.7.6     2021-11-29 [1] CRAN (R 4.1.2)
#>  stringr       1.4.0     2019-02-10 [1] CRAN (R 4.1.1)
#>  styler        1.6.2     2021-09-23 [1] CRAN (R 4.1.1)
#>  tibble        3.1.6     2021-11-07 [1] CRAN (R 4.1.2)
#>  utf8          1.2.2     2021-07-24 [1] CRAN (R 4.1.1)
#>  vctrs         0.3.8     2021-04-29 [1] CRAN (R 4.1.1)
#>  withr         2.4.3     2021-11-30 [1] CRAN (R 4.1.2)
#>  xfun          0.29      2021-12-14 [1] CRAN (R 4.1.2)
#>  xml2          1.3.3     2021-11-30 [1] CRAN (R 4.1.2)
#>  yaml          2.2.2     2022-01-25 [1] CRAN (R 4.1.2)
#> 
#>  [1] C:/Users/andre/Documents/R/win-library/4.1
#>  [2] C:/Program Files/R/R-4.1.2/library
#> 
#> ------------------------------------------------------------------------------

but works with version 0.1.8:

remotes::install_version("osmdata", "0.1.8", quiet = TRUE)
library(osmdata)
#> Data (c) OpenStreetMap contributors, ODbL 1.0. https://www.openstreetmap.org/copyright
id <- c (1489221200, 1489221321, 1489221491)
opq_osm_id (type = "node", id = id) %>%
  opq_string () %>%
  osmdata_sf ()
#> Object of class 'osmdata' with:
#>                  $bbox : 
#>         $overpass_call : The call submitted to the overpass API
#>                  $meta : metadata including timestamp and version numbers
#>            $osm_points : 'sf' Simple Features Collection with 3 points
#>             $osm_lines : NULL
#>          $osm_polygons : 'sf' Simple Features Collection with 0 polygons
#>        $osm_multilines : NULL
#>     $osm_multipolygons : NULL

Created on 2022-03-10 by the reprex package (v2.0.1)

Maybe it's intended, but I didn't find anything useful in the NEWS file.

Moreover, I notice that the following fails with a different error in the current CRAN version:

remotes::install_cran("osmdata")
#> Installing 1 packages: osmdata
#> Installing package into 'C:/Users/andre/Documents/R/win-library/4.1'
#> (as 'lib' is unspecified)
#> package 'osmdata' successfully unpacked and MD5 sums checked
#> 
#> The downloaded binary packages are in
#>  C:\Users\andre\AppData\Local\Temp\RtmpcBCyvl\downloaded_packages
library(osmdata)
#> Data (c) OpenStreetMap contributors, ODbL 1.0. https://www.openstreetmap.org/copyright
id <- c (1489221200L)
opq_osm_id (type = "node", id = id) %>%
  opq_string () %>%
  osmdata_sf ()
#> Error in opq_osm_id(type = "node", id = id): id must be character or numeric.

Created on 2022-03-10 by the reprex package (v2.0.1)

Session info
sessioninfo::session_info()
#> - Session info ---------------------------------------------------------------
#>  setting  value
#>  version  R version 4.1.2 (2021-11-01)
#>  os       Windows 10 x64 (build 19042)
#>  system   x86_64, mingw32
#>  ui       RTerm
#>  language (EN)
#>  collate  English_United Kingdom.1252
#>  ctype    English_United Kingdom.1252
#>  tz       Europe/Berlin
#>  date     2022-03-10
#>  pandoc   2.16.2 @ C:/PROGRA~1/Pandoc/ (via rmarkdown)
#> 
#> - Packages -------------------------------------------------------------------
#>  package     * version date (UTC) lib source
#>  backports     1.4.1   2021-12-13 [1] CRAN (R 4.1.2)
#>  cli           3.2.0   2022-02-14 [1] CRAN (R 4.1.2)
#>  crayon        1.5.0   2022-02-14 [1] CRAN (R 4.1.2)
#>  curl          4.3.2   2021-06-23 [1] CRAN (R 4.1.1)
#>  digest        0.6.29  2021-12-01 [1] CRAN (R 4.1.2)
#>  ellipsis      0.3.2   2021-04-29 [1] CRAN (R 4.1.1)
#>  evaluate      0.14    2019-05-28 [1] CRAN (R 4.1.1)
#>  fansi         1.0.2   2022-01-14 [1] CRAN (R 4.1.2)
#>  fastmap       1.1.0   2021-01-25 [1] CRAN (R 4.1.1)
#>  fs            1.5.2   2021-12-08 [1] CRAN (R 4.1.2)
#>  generics      0.1.2   2022-01-31 [1] CRAN (R 4.1.2)
#>  glue          1.6.2   2022-02-24 [1] CRAN (R 4.1.2)
#>  highr         0.9     2021-04-16 [1] CRAN (R 4.1.1)
#>  htmltools     0.5.2   2021-08-25 [1] CRAN (R 4.1.1)
#>  httr          1.4.2   2020-07-20 [1] CRAN (R 4.1.1)
#>  jsonlite      1.8.0   2022-02-22 [1] CRAN (R 4.1.2)
#>  knitr         1.37    2021-12-16 [1] CRAN (R 4.1.2)
#>  lattice       0.20-45 2021-09-22 [2] CRAN (R 4.1.2)
#>  lifecycle     1.0.1   2021-09-24 [1] CRAN (R 4.1.1)
#>  lubridate     1.8.0   2021-10-07 [1] CRAN (R 4.1.1)
#>  magrittr      2.0.2   2022-01-26 [1] CRAN (R 4.1.2)
#>  osmdata     * 0.1.9   2022-01-26 [1] CRAN (R 4.1.2)
#>  pillar        1.7.0   2022-02-01 [1] CRAN (R 4.1.2)
#>  pkgconfig     2.0.3   2019-09-22 [1] CRAN (R 4.1.1)
#>  purrr         0.3.4   2020-04-17 [1] CRAN (R 4.1.1)
#>  R.cache       0.15.0  2021-04-30 [1] CRAN (R 4.1.1)
#>  R.methodsS3   1.8.1   2020-08-26 [1] CRAN (R 4.1.1)
#>  R.oo          1.24.0  2020-08-26 [1] CRAN (R 4.1.1)
#>  R.utils       2.11.0  2021-09-26 [1] CRAN (R 4.1.1)
#>  R6            2.5.1   2021-08-19 [1] CRAN (R 4.1.1)
#>  Rcpp          1.0.8   2022-01-13 [1] CRAN (R 4.1.2)
#>  remotes       2.4.2   2021-11-30 [1] CRAN (R 4.1.2)
#>  reprex        2.0.1   2021-08-05 [1] CRAN (R 4.1.1)
#>  rlang         1.0.2   2022-03-04 [1] CRAN (R 4.1.2)
#>  rmarkdown     2.11    2021-09-14 [1] CRAN (R 4.1.1)
#>  rstudioapi    0.13    2020-11-12 [1] CRAN (R 4.1.1)
#>  rvest         1.0.2   2021-10-16 [1] CRAN (R 4.1.1)
#>  sessioninfo   1.2.2   2021-12-06 [1] CRAN (R 4.1.2)
#>  sp            1.4-6   2021-11-14 [1] CRAN (R 4.1.2)
#>  stringi       1.7.6   2021-11-29 [1] CRAN (R 4.1.2)
#>  stringr       1.4.0   2019-02-10 [1] CRAN (R 4.1.1)
#>  styler        1.6.2   2021-09-23 [1] CRAN (R 4.1.1)
#>  tibble        3.1.6   2021-11-07 [1] CRAN (R 4.1.2)
#>  utf8          1.2.2   2021-07-24 [1] CRAN (R 4.1.1)
#>  vctrs         0.3.8   2021-04-29 [1] CRAN (R 4.1.1)
#>  withr         2.4.3   2021-11-30 [1] CRAN (R 4.1.2)
#>  xfun          0.29    2021-12-14 [1] CRAN (R 4.1.2)
#>  xml2          1.3.3   2021-11-30 [1] CRAN (R 4.1.2)
#>  yaml          2.2.2   2022-01-25 [1] CRAN (R 4.1.2)
#> 
#>  [1] C:/Users/andre/Documents/R/win-library/4.1
#>  [2] C:/Program Files/R/R-4.1.2/library
#> 
#> ------------------------------------------------------------------------------
@mpadge
Copy link
Member

mpadge commented Mar 10, 2022

Thanks @agila5, I'll check it out next week. Looks indeed like some kinda 🐛, and there have been a few backend updates to opq functions lately, so you're likely right

@assignUser
Copy link

I just ran into this in an attempt to not map over queries and be kind to the overpass api ^^

The issue is this guard https://github.com/ropensci/osmdata/blob/main/R/opq.R#L426
Looking at opq and opq_string https://github.dev/ropensci/osmdata/blob/main/R/opq.R#L667-L668
I do not see an obvious reason why multiple ids would not work. Manually gsubing in multiple ids into the opq_string also works just fine and returns osmdata with an sf::st_sfc.

Unless I missed something that check should be superfluous, happy to open a PR :)

@assignUser
Copy link

An easier workaround is:

id <- c(1489221200, 1489221321, 1489221491)
id <- paste(id, collapse = ",")

@Robsteranium
Copy link

Indeed if we ignore the guard clause and create the equivalent opq object it works fine:

opq <- opq(1:4); opq$id <- list(type="node", id=c(1489221200, 1489221321, 1489221491))
opq |> osmdata_sf()

I suspect the guard can be removed.

@agila5 the failure with integers is expected, per the docs:

official OSM identifiers ... must be entered as either a character or numeric value (because R does not support long-form integers)

@mpadge
Copy link
Member

mpadge commented Nov 28, 2022

Thanks to @jmaspons for fixing this via PR linked above.

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

Successfully merging a pull request may close this issue.

4 participants