osmdata icon indicating copy to clipboard operation
osmdata copied to clipboard

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

Open elipousson opened this issue 3 years ago • 1 comments

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

elipousson avatar Nov 10 '22 04:11 elipousson

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.

mpadge avatar Nov 10 '22 08:11 mpadge