Skip to content

Commit ffc5b48

Browse files
committed
Rename features -> tags where it make sense
Feature refers to represented entities represented by OSM objects. Tags are the attributes of OSM objects that characterize the features.
1 parent 66f323f commit ffc5b48

File tree

5 files changed

+68
-65
lines changed

5 files changed

+68
-65
lines changed

R/opq.R

Lines changed: 53 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -206,11 +206,11 @@ opq <- function (bbox = NULL, nodes_only,
206206
}
207207

208208
# used in the following filter_osm_tags fn
209-
paste_features <- function (key, value, key_pre = "", bind = "=",
210-
match_case = FALSE, value_exact = FALSE) {
209+
paste_tags <- function (key, value, key_pre = "", bind = "=",
210+
match_case = FALSE, value_exact = FALSE) {
211211
if (is.null (value)) {
212212

213-
feature <- ifelse (substring (key, 1, 1) == "!",
213+
tag <- ifelse (substring (key, 1, 1) == "!",
214214
sprintf ('[!"%s"]', substring (key, 2, nchar (key))),
215215
sprintf ('["%s"]', key)
216216
)
@@ -235,17 +235,17 @@ paste_features <- function (key, value, key_pre = "", bind = "=",
235235
key_pre <- ""
236236
}
237237
}
238-
feature <- paste0 (sprintf (
238+
tag <- paste0 (sprintf (
239239
'[%s"%s"%s"%s"',
240240
key_pre, key, bind, value
241241
))
242242
if (!match_case) {
243-
feature <- paste0 (feature, ",i")
243+
tag <- paste0 (tag, ",i")
244244
}
245-
feature <- paste0 (feature, "]")
245+
tag <- paste0 (tag, "]")
246246
}
247247

248-
return (feature)
248+
return (tag)
249249
}
250250

251251
#' Add tags to all current statements of an Overpass query
@@ -323,7 +323,7 @@ paste_features <- function (key, value, key_pre = "", bind = "=",
323323
#'
324324
#' # Get objects with keys (`natural` OR `waterway`) AND `name`
325325
#' q_keys <- opq ("Badia del Vallès", osm_types = "nwr", out = "tags") |>
326-
#' add_osm_tags (features = list (natural = NULL, waterway = NULL)) |>
326+
#' add_osm_tags (tags = list (natural = NULL, waterway = NULL)) |>
327327
#' filter_osm_tags (key = "name")
328328
#' cat (opq_string (q_keys))
329329
#' }
@@ -353,16 +353,16 @@ filter_osm_tags <- function (opq,
353353
value <- NULL
354354
}
355355

356-
feature <- paste_features (
356+
tags <- paste_tags (
357357
key, value, bind_key_pre$key_pre, bind_key_pre$bind,
358358
match_case, value_exact
359359
)
360-
feature <- paste (feature, collapse = " ")
360+
tags <- paste (tags, collapse = " ")
361361

362362
if (is.null (opq$features)) {
363-
opq$features <- feature
363+
opq$features <- tags
364364
} else {
365-
opq$features <- paste (opq$features, feature)
365+
opq$features <- paste (opq$features, tags)
366366
}
367367

368368
if (any (w <- !grepl ("\\[(\\\"|~)", opq$features))) {
@@ -419,7 +419,7 @@ add_osm_feature <- function (opq, # TODO: DEPRECATE
419419
#' @noRd
420420
set_bind_key_pre <- function (key_exact = TRUE,
421421
value_exact = TRUE,
422-
features = NULL,
422+
tags = NULL,
423423
bind = "=",
424424
key_pre = "") {
425425
if (!is.null (value_exact)) {
@@ -428,35 +428,35 @@ set_bind_key_pre <- function (key_exact = TRUE,
428428

429429
check_bind_key_pre (bind, key_pre)
430430

431-
if (!is.null (features)) {
431+
if (!is.null (tags)) {
432432
if (length (bind) == 1) {
433-
bind <- rep_len (bind, length (features))
434-
} else if (!identical_length (features, bind)) {
433+
bind <- rep_len (bind, length (tags))
434+
} else if (!identical_length (tags, bind)) {
435435
stop (
436-
"bind must be length 1 or the same length as features"
436+
"bind must be length 1 or the same length as tags"
437437
)
438438
}
439439

440440
if (length (key_pre) == 1) {
441-
key_pre <- rep_len (key_pre, length (features))
442-
} else if (!identical_length (features, key_pre)) {
441+
key_pre <- rep_len (key_pre, length (tags))
442+
} else if (!identical_length (tags, key_pre)) {
443443
stop (
444-
"key_pre must be length 1 or the same length as features"
444+
"key_pre must be length 1 or the same length as tags"
445445
)
446446
}
447447
}
448448

449-
features_len <- 1L
450-
if (!is.null (features)) {
451-
features_len <- length (features)
449+
tags_len <- 1L
450+
if (!is.null (tags)) {
451+
tags_len <- length (tags)
452452
}
453453

454454
if (!is.null (value_exact) && !value_exact) {
455-
bind <- rep_len ("~", features_len)
455+
bind <- rep_len ("~", tags_len)
456456
}
457457

458458
if (!is.null (key_exact) && !key_exact) {
459-
key_pre <- rep_len ("~", features_len)
459+
key_pre <- rep_len ("~", tags_len)
460460
}
461461

462462
list (
@@ -510,7 +510,7 @@ check_bind_key_pre <- function (bind = "=", key_pre = "") {
510510
#'
511511
#' @inheritParams filter_osm_tags
512512
#' @inheritSection filter_osm_tags `filter_osm_tags` vs `add_osm_tags`
513-
#' @param features A named list or vector with the format `list("<key>" =
513+
#' @param tags A named list or vector with the format `list("<key>" =
514514
#' "<value>")` or `c("<key>" = "<value>")` or a character vector of
515515
#' key-value pairs with keys and values enclosed in escape-formatted
516516
#' quotations. See examples for details.
@@ -527,13 +527,13 @@ check_bind_key_pre <- function (bind = "=", key_pre = "") {
527527
#' @examples
528528
#' \dontrun{
529529
#' q <- opq ("portsmouth usa") |>
530-
#' add_osm_tags (features = list (
530+
#' add_osm_tags (tags = list (
531531
#' "amenity" = "restaurant",
532532
#' "amenity" = "pub"
533533
#' ))
534534
#'
535535
#' q <- opq ("portsmouth usa") |>
536-
#' add_osm_tags (features = c (
536+
#' add_osm_tags (tags = c (
537537
#' "\"amenity\"=\"restaurant\"",
538538
#' "\"amenity\"=\"pub\""
539539
#' ))
@@ -550,12 +550,12 @@ check_bind_key_pre <- function (bind = "=", key_pre = "") {
550550
#'
551551
#' # Get objects with keys (`natural` OR `waterway`) AND `name`
552552
#' q_keys <- opq ("Badia del Vallès", osm_types = "nwr", out = "tags") |>
553-
#' add_osm_tags (features = list (natural = NULL, waterway = NULL)) |>
553+
#' add_osm_tags (tags = list (natural = NULL, waterway = NULL)) |>
554554
#' filter_osm_tags (key = "name")
555555
#' cat (opq_string (q_keys))
556556
#' }
557557
add_osm_tags <- function (opq,
558-
features,
558+
tags,
559559
bbox = NULL,
560560
key_exact = TRUE,
561561
value_exact = TRUE) {
@@ -572,44 +572,45 @@ add_osm_tags <- function (opq,
572572
opq$suffix <- ");\n(._;>;);\nout body;"
573573
}
574574

575-
check_features (features)
575+
check_tags (tags)
576576

577-
if (is_named (features)) {
577+
if (is_named (tags)) {
578578
bind_key_pre <-
579579
set_bind_key_pre (
580-
features = features,
580+
tags = tags,
581581
value_exact = value_exact,
582582
key_exact = key_exact
583583
)
584584

585-
features <- mapply (
585+
tags <- mapply (
586586
function (key, value, key_pre, bind) {
587-
paste_features (key, value,
587+
paste_tags (key, value,
588588
key_pre = key_pre, bind = bind,
589589
match_case = TRUE, value_exact = value_exact
590590
)
591591
},
592-
key = names (features), value = features,
592+
key = names (tags), value = tags,
593593
key_pre = bind_key_pre$key_pre, bind = bind_key_pre$bind,
594594
SIMPLIFY = FALSE
595595
)
596-
features <- as.character (features)
596+
tags <- as.character (tags)
597597

598598
}
599599

600-
index <- which (!grepl ("^\\[", features))
601-
features [index] <- paste0 ("[", features [index])
602-
index <- which (!grepl ("\\]$", features))
603-
features [index] <- paste0 (features [index], "]")
600+
index <- which (!grepl ("^\\[", tags))
601+
tags [index] <- paste0 ("[", tags [index])
602+
index <- which (!grepl ("\\]$", tags))
603+
tags [index] <- paste0 (tags [index], "]")
604604

605-
opq$features <- unique (c (opq$features, features))
605+
opq$features <- unique (c (opq$features, tags))
606606

607607
opq
608608
}
609609

610610
#' @rdname add_osm_tags
611611
#'
612612
#' @description `add_osm_features()` will be DEPRECATED in future versions.
613+
#' @param features Same as `tags`.
613614
#'
614615
#' @export
615616
add_osm_features <- function (opq, # TODO: DEPRECATE
@@ -619,7 +620,7 @@ add_osm_features <- function (opq, # TODO: DEPRECATE
619620
value_exact = TRUE) {
620621
add_osm_tags (
621622
opq = opq,
622-
features = features,
623+
tags = features,
623624
bbox = bbox,
624625
key_exact = key_exact,
625626
value_exact = value_exact
@@ -644,19 +645,19 @@ is_escape_delimited <- function (x) {
644645
#' Check if tags is provided and uses the required class and formatting
645646
#'
646647
#' @noRd
647-
check_features <- function (features) {
648-
if (missing (features)) {
649-
stop ("features must be provided", call. = FALSE)
648+
check_tags <- function (tags) {
649+
if (missing (tags)) {
650+
stop ("tags must be provided", call. = FALSE)
650651
}
651652

652653
stopifnot (
653-
"features must be a list or character vector." =
654-
is.character (features) | is.list (features)
654+
"tags must be a list or character vector." =
655+
is.character (tags) | is.list (tags)
655656
)
656657

657-
if (!is_named (features) && is_escape_delimited (features)) {
658+
if (!is_named (tags) && is_escape_delimited (tags)) {
658659
stop (
659-
"features must be a named list or vector or a character vector ",
660+
"tags must be a named list or vector or a character vector ",
660661
"enclosed in escape delimited quotations (see examples)",
661662
call. = FALSE
662663
)
@@ -891,7 +892,7 @@ opq_enclosing <- function (lon = NULL, lat = NULL,
891892
prefix <- paste0 ("[out:xml][timeout:", timeout, "]")
892893
suffix <- ");\n(._;>;);\nout;"
893894

894-
features <- paste_features (key,
895+
tags <- paste_tags (key,
895896
value,
896897
value_exact = TRUE,
897898
match_case = TRUE
@@ -900,7 +901,7 @@ opq_enclosing <- function (lon = NULL, lat = NULL,
900901
bbox = bbox,
901902
prefix = paste0 (prefix, ";\n(\n"),
902903
suffix = suffix,
903-
features = features
904+
features = tags
904905
)
905906
class (res) <- c (class (res), "overpass_query")
906907
attr (res, "datetime") <- attr (res, "datetime2") <- NULL

man/add_osm_tags.Rd

Lines changed: 7 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/filter_osm_tags.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/test-osmdata.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ test_that ("add_osm_features", {
400400
qry <- opq (bbox = c (-0.118, 51.514, -0.115, 51.517))
401401
expect_error (
402402
qry <- add_osm_features (qry),
403-
"features must be provided"
403+
"tags must be provided"
404404
)
405405

406406
qry$bbox <- NULL
@@ -413,7 +413,7 @@ test_that ("add_osm_features", {
413413

414414
expect_error (
415415
qry <- add_osm_features (qry, features = "a"),
416-
"features must be a named list or vector or a character vector enclosed in escape delimited quotations \\(see examples\\)"
416+
"tags must be a named list or vector or a character vector enclosed in escape delimited quotations \\(see examples\\)"
417417
)
418418

419419
bbox <- c (-0.118, 51.514, -0.115, 51.517)

tests/testthat/test-set_bind_key_pre.R

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,22 @@
44
# package developers decide the option could be useful.
55

66
test_that ("set_bind_key_pre errors", {
7-
features <- list ("amenity" = "restaurant", "amenity" = "pub")
7+
tags <- list ("amenity" = "restaurant", "amenity" = "pub")
88

99
expect_error (
1010
set_bind_key_pre (
11-
features = features,
11+
tags = tags,
1212
bind = rep ("=", 3)
1313
),
14-
"bind must be length 1 or the same length as features"
14+
"bind must be length 1 or the same length as tags"
1515
)
1616

1717
expect_error (
1818
set_bind_key_pre (
19-
features = features,
19+
tags = tags,
2020
key_pre = rep ("", 3)
2121
),
22-
"key_pre must be length 1 or the same length as features"
22+
"key_pre must be length 1 or the same length as tags"
2323
)
2424

2525
expect_error (

0 commit comments

Comments
 (0)