Skip to content

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

@elipousson

Description

@elipousson

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions