From 1fc7ba80f32349c00b1c7cc145d1c1eebb399c0e Mon Sep 17 00:00:00 2001 From: Joan Maspons Date: Thu, 13 Jun 2024 21:16:33 +0200 Subject: [PATCH] Fix concatenation of xml_nodeset for calls in batches Only the first node of each batch after the first were included. --- R/osm_get_changesets.R | 6 ++++-- R/osm_get_gpx_metadata.R | 6 ++++-- R/osm_get_notes.R | 6 ++++-- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/R/osm_get_changesets.R b/R/osm_get_changesets.R index 64e5dbb9..e9663bff 100644 --- a/R/osm_get_changesets.R +++ b/R/osm_get_changesets.R @@ -100,8 +100,10 @@ osm_get_changesets <- function(changeset_id, include_discussion = FALSE, } } else if (format == "xml") { out <- xml2::xml_new_root(outL[[1]]) - for (i in seq_len(length(outL) - 1)) { - xml2::xml_add_child(out, xml2::xml_child(outL[[i + 1]])) + for (i in seq_along(outL[-1]) + 1) { + lapply(xml2::xml_children(outL[[i]]), function(node) { + xml2::xml_add_child(out, node) + }) } } else if (format == "json") { out <- outL[[1]] diff --git a/R/osm_get_gpx_metadata.R b/R/osm_get_gpx_metadata.R index d5157f92..1c3ee3da 100644 --- a/R/osm_get_gpx_metadata.R +++ b/R/osm_get_gpx_metadata.R @@ -46,8 +46,10 @@ osm_get_gpx_metadata <- function(gpx_id, format = c("R", "xml")) { out <- do.call(rbind, outL) } else if (format == "xml") { out <- xml2::xml_new_root(outL[[1]]) - for (i in seq_len(length(outL) - 1)) { - xml2::xml_add_child(out, xml2::xml_child(outL[[i + 1]])) + for (i in seq_along(outL[-1]) + 1) { + lapply(xml2::xml_children(outL[[i]]), function(node) { + xml2::xml_add_child(out, node) + }) } } } diff --git a/R/osm_get_notes.R b/R/osm_get_notes.R index d52026f3..f063bb38 100644 --- a/R/osm_get_notes.R +++ b/R/osm_get_notes.R @@ -92,8 +92,10 @@ osm_get_notes <- function(note_id, format = c("R", "xml", "rss", "json", "gpx")) out <- do.call(rbind, outL) } else if (format %in% c("xml", "rss", "gpx")) { out <- xml2::xml_new_root(outL[[1]]) - for (i in seq_len(length(outL) - 1)) { - xml2::xml_add_child(out, xml2::xml_child(outL[[i + 1]])) + for (i in seq_along(outL[-1]) + 1) { + lapply(xml2::xml_children(outL[[i]]), function(node) { + xml2::xml_add_child(out, node) + }) } # TODO: remove namespaces for format %in% c("rss", "gpx"). xml2::xml_structure(out) [ VS ] # xml namespace https://community.rstudio.com/t/adding-nodes-in-xml2-how-to-avoid-duplicate-default-namespaces/84870/