Skip to content

Commit

Permalink
Add get map data function documentation and export function
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksanderbl29 committed Aug 23, 2024
1 parent ae7642e commit 587f9af
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 3 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

export(available_sections)
export(dawa)
export(get_map_data)
export(status_check)
18 changes: 15 additions & 3 deletions R/get_map_data.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
#' Fetch map data to use with `{sf}`.
#'
#' @param type Defines the type of map data to request from DAWA. Run
#' `available_sections(format = "geojson")` to your options.
#'
#' @return Returns a `data.frame` object that contains polygons for the section
#' provided.
#' @export
#'
#' @examples
#' x <- get_map_data("regioner")
#' ggplot2::ggplot(x) +
#' ggplot2::geom_sf()
get_map_data <- function(type) {

if (type == "afstemningsomraader") {
section <- "afstemningsomraader"
if (!type %in% available_sections(format = "geojson", verbose = FALSE)) {
cli::cli_abort("You have provided type {.var {type}} that is not compatible with this function.")
}

api_response <- dawa(
Expand All @@ -14,7 +27,6 @@ get_map_data <- function(type) {
api_response,
quiet = TRUE
)

map_data <- sf::st_as_sf(resp_st)

return(map_data)
Expand Down
24 changes: 24 additions & 0 deletions man/get_map_data.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 587f9af

Please sign in to comment.