diff --git a/R/opq.R b/R/opq.R index 00732883..f42f9cf2 100644 --- a/R/opq.R +++ b/R/opq.R @@ -339,8 +339,13 @@ add_osm_feature <- function (opq, key, value, bind_key_pre$key_pre, bind_key_pre$bind, match_case, value_exact ) + feature<- paste (feature, collapse = " ") - opq$features <- paste0 (c (opq$features, feature), collapse = "") + if (is.null (opq$features)) { + opq$features <- feature + } else { + opq$features <- paste (opq$features, feature) + } if (any (w <- !grepl("\\[(\\\"|~)", opq$features))) { warning( @@ -527,19 +532,24 @@ add_osm_features <- function (opq, key_exact = key_exact ) - features <- - paste0 ( - bind_key_pre$key_pre, '\"', names (features), '\"', - bind_key_pre$bind, '\"', features, '\"' - ) + features <- mapply (function (key, value, key_pre, bind) { + paste_features (key, value, key_pre = key_pre, bind = bind, + match_case = TRUE, value_exact = value_exact) + }, + key = names (features), value = features, + key_pre = bind_key_pre$key_pre, bind = bind_key_pre$bind, + SIMPLIFY = FALSE + ) + features <- as.character (features) + } index <- which (!grepl ("^\\[", features)) - features [index] <- paste0 (" [", features [index]) + features [index] <- paste0 ("[", features [index]) index <- which (!grepl ("\\]$", features)) features [index] <- paste0 (features [index], "]") - opq$features <- features + opq$features <- unique (c (opq$features, features)) opq } diff --git a/tests/testthat/test-osmdata.R b/tests/testthat/test-osmdata.R index 49646425..471762eb 100644 --- a/tests/testthat/test-osmdata.R +++ b/tests/testthat/test-osmdata.R @@ -80,9 +80,9 @@ test_that ("add feature", { add_osm_feature (key = "natural", value = "peak"), "The query will request objects whith only a negated key " ) - expect_identical(qry7$features, "[\"name\"][!\"name:ca\"]") - expect_identical(qry8$features, "[\"natural\"=\"peak\"][!\"ele\"]") - expect_identical(qry9$features, "[!\"ele\"][\"natural\"=\"peak\"]") + expect_identical(qry7$features, "[\"name\"] [!\"name:ca\"]") + expect_identical(qry8$features, "[\"natural\"=\"peak\"] [!\"ele\"]") + expect_identical(qry9$features, "[!\"ele\"] [\"natural\"=\"peak\"]") }) test_that ("query_errors", {