Change tags
from a list column <-> columns for each key in wide format
Source: R/tags_list-wide.r
tags_list-wide.Rd
Objects of classes osmapi_objects
and osmapi_changesets
can represent the tags in a column with a list with
a data.frame for each row with 2 columns for keys and values, or by columns for each key. These functions allow
to change the format of the tags.
Arguments
- x
An
osmapi_objects
orosmapi_changesets
objects as returned by, for example,osm_get_objects()
orosm_get_changesets()
.
Value
A data frame with the same class and data than the original (osmapi_objects
or osmapi_changesets
) but with the
specified tags' format.
Details
Both formats have advantages. Tags in a list of data.frames is a more compact representation and there is no risk of clashes of column names and tag keys. Tags in columns make it easier to select rows by tags as in a regular data.frame. Column name clashes are resolved and the original key names restored when transformed to tags list format.
By default, functions returning osmapi_objects
or osmapi_changesets
objects, use the the tags in a list column,
but can return the results in a wide format using the parameter tags_in_columns = TRUE
.
Examples
if (FALSE) {
peaks_wide <- osm_get_objects(
osm_type = "nodes", osm_id = c(35308286, 1935675367), tags_in_columns = TRUE
)
peaks_list <- tags_wide2list(peaks_wide)
# tags in list format
peaks_list$tags
# Select peaks with `prominence` tag
peaks_wide[!is.na(peaks_wide$prominence), ]
peaks_list[sapply(peaks_list$tags, function(x) any(x$key == "prominence")), ]
cities_list <- osm_get_objects(osm_type = "relations", osm_id = c("40581", "341530"))
# Column name clash:
cities_wide <- tags_list2wide(cities_list)
}