From 4db746012c578989f1f6a0665e950bd72ff1f37f Mon Sep 17 00:00:00 2001 From: aleksanderbl29 <73799306+aleksanderbl29@users.noreply.github.com> Date: Fri, 20 Sep 2024 10:56:24 +0200 Subject: [PATCH 1/2] Add cli progress messages to get map data func --- R/get_map_data.R | 7 +++++++ tests/testthat/_snaps/get_map_data-kommuner.md | 4 ++++ tests/testthat/_snaps/get_map_data-politikredse.md | 4 ++++ tests/testthat/_snaps/get_map_data-regioner.md | 4 ++++ tests/testthat/_snaps/get_map_data-vote.md | 4 ++++ 5 files changed, 23 insertions(+) diff --git a/R/get_map_data.R b/R/get_map_data.R index f0afb66..147fac8 100644 --- a/R/get_map_data.R +++ b/R/get_map_data.R @@ -26,16 +26,23 @@ get_map_data <- function(type) { check_sf_installation(verbose = FALSE) + cli::cli_progress_message("Fetching data from the API") + api_response <- dawa( section = type, format = "geojson", verbose = FALSE ) + cli::cli_progress_message("Reading data to `st`") + resp_st <- sf::st_read( api_response, quiet = TRUE ) + + cli::cli_progress_message("Converting map data to `sf` object") + map_data <- sf::st_as_sf(resp_st) return(map_data) diff --git a/tests/testthat/_snaps/get_map_data-kommuner.md b/tests/testthat/_snaps/get_map_data-kommuner.md index 3ddc6a2..faf4796 100644 --- a/tests/testthat/_snaps/get_map_data-kommuner.md +++ b/tests/testthat/_snaps/get_map_data-kommuner.md @@ -2,6 +2,10 @@ Code get_map_data(type = "kommuner") + Message + Fetching data from the API + Reading data to `st` + Converting map data to `sf` object Output Simple feature collection with 99 features and 11 fields Geometry type: MULTIPOLYGON diff --git a/tests/testthat/_snaps/get_map_data-politikredse.md b/tests/testthat/_snaps/get_map_data-politikredse.md index 961a0e7..175f1f9 100644 --- a/tests/testthat/_snaps/get_map_data-politikredse.md +++ b/tests/testthat/_snaps/get_map_data-politikredse.md @@ -2,6 +2,10 @@ Code get_map_data(type = "politikredse") + Message + Fetching data from the API + Reading data to `st` + Converting map data to `sf` object Output Simple feature collection with 12 features and 8 fields Geometry type: MULTIPOLYGON diff --git a/tests/testthat/_snaps/get_map_data-regioner.md b/tests/testthat/_snaps/get_map_data-regioner.md index 90ff753..da49f37 100644 --- a/tests/testthat/_snaps/get_map_data-regioner.md +++ b/tests/testthat/_snaps/get_map_data-regioner.md @@ -2,6 +2,10 @@ Code get_map_data(type = "regioner") + Message + Fetching data from the API + Reading data to `st` + Converting map data to `sf` object Output Simple feature collection with 5 features and 9 fields Geometry type: MULTIPOLYGON diff --git a/tests/testthat/_snaps/get_map_data-vote.md b/tests/testthat/_snaps/get_map_data-vote.md index 4ac258e..4899375 100644 --- a/tests/testthat/_snaps/get_map_data-vote.md +++ b/tests/testthat/_snaps/get_map_data-vote.md @@ -2,6 +2,10 @@ Code get_map_data(type = "afstemningsomraader") + Message + Fetching data from the API + Reading data to `st` + Converting map data to `sf` object Output Simple feature collection with 1298 features and 23 fields Geometry type: MULTIPOLYGON From f9c8a377b025eb2f4de5ea310fcb4006a92d9561 Mon Sep 17 00:00:00 2001 From: Aleksander Bang-Larsen Date: Fri, 4 Oct 2024 10:04:30 +0200 Subject: [PATCH 2/2] Update .Rprofile --- .Rprofile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.Rprofile b/.Rprofile index 926bcde..4659e30 100644 --- a/.Rprofile +++ b/.Rprofile @@ -21,3 +21,5 @@ if (interactive()) { suppressMessages(require(testthat)) devtools::dev_sitrep() } + +