-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Vectorized version of osm_read_note()
- Loading branch information
Showing
8 changed files
with
63 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# Vectorized version of osm_read_note | ||
|
||
#' Get notes | ||
#' | ||
#' Returns the existing note with the given ID. | ||
#' | ||
#' @param note_id Note id represented by a numeric or a character value. | ||
#' @param format Format of the output. Can be `R` (default), `xml`, `rss`, `json` or `gpx`. | ||
#' | ||
#' @return | ||
#' If `format = "R"`, returns a data frame with one map note per row. If `format = "json"`, returns a list with the json | ||
#' structure. For `format` in `xml`, `rss`, and `gpx`, a [xml2::xml_document-class] with the corresponding format. | ||
#' @family get notes' functions | ||
#' @export | ||
#' | ||
#' @examples | ||
#' \dontrun{ | ||
#' note <- osm_get_notes(note_id = "2067786") | ||
#' note | ||
#' } | ||
osm_get_notes <- function(note_id, format = c("R", "xml", "rss", "json", "gpx")) { | ||
format <- match.arg(format) | ||
|
||
if (length(note_id) == 1) { | ||
out <- osm_read_note(note_id = note_id, format = format) | ||
} else { | ||
outL <- lapply(note_id, function(id) { | ||
osm_read_note(note_id = id, format = format) | ||
}) | ||
|
||
if (format == "R") { | ||
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]])) | ||
} | ||
} else if (format == "json") { | ||
out <- outL | ||
} | ||
} | ||
|
||
return(out) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters