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

[FEATURE] Add support for named lists to add_osm_features() #277

Open
elipousson opened this issue Nov 10, 2022 · 1 comment
Open

[FEATURE] Add support for named lists to add_osm_features() #277

elipousson opened this issue Nov 10, 2022 · 1 comment

Comments

@elipousson
Copy link
Contributor

Instead of requiring the features parameter for add_osm_features() be provided with escape-formatted quotations, it would be great to support a named list. The following reprex shows how this could be added with a fairly minor change. Happy to open a pull request if you're interested!

library(osmdata)
#> Data (c) OpenStreetMap contributors, ODbL 1.0. https://www.openstreetmap.org/copyright

q1 <- opq ("portsmouth usa") %>%
  add_osm_features (features = c (
    "\"amenity\"=\"restaurant\"",
    "\"amenity\"=\"pub\""
  ))

add_osm_features_ext <- function(opq, features, bbox = NULL) {
  if (is.list(features)) {
    features <- paste0('\"', names(features), '\"=\"', features, '\"')
  }
  add_osm_features(opq, features, bbox)
}

q2 <- opq("portsmouth usa") %>%
  add_osm_features_ext(
    features = list(
      "amenity" = "restaurant",
      "amenity" = "pub"
    )
  )

identical(q1, q2)
#> [1] TRUE

Created on 2022-11-09 with reprex v2.0.2

@mpadge
Copy link
Member

mpadge commented Nov 10, 2022

Great idea @elipousson, a PR would be very welcome. I was never really happy with the whole escaped-quotes bagagge, but the annoyance level was only ever trivial, so i never did anything about it. Lists is a great solution, thanks! You'll just need to make sure all tests pass - ping me if you've got any questions.

elipousson added a commit to elipousson/osmdata that referenced this issue Nov 14, 2022
- update add_osm_features per ropensci#277 includes adding a helper function set_bind_key_pre() to share handling of key_exact and value_exact w/ add_osm_feature
- add option to opq_osm_id to pass id w/ prefixed type, e.g. "relation/11158003"
- expand tests for add_osm_features() and opq_osm_id()
mpadge added a commit that referenced this issue Nov 24, 2022
update `add_osm_features()` per #277   minor bugfix for `available_tags()`   possible `opq_osm_id()` feature addition
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