Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update snapshots pr 20 oct 2024 #56

Closed
wants to merge 41 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
038030e
Further testing of map function alternatives
aleksanderbl29 Sep 22, 2024
a3e78c9
Increment version number to 0.1.0.9000
aleksanderbl29 Sep 22, 2024
8388006
More benchmarking
aleksanderbl29 Sep 22, 2024
eaf0421
Use dep memoise
aleksanderbl29 Sep 22, 2024
75bf139
Update renv snapshot
aleksanderbl29 Sep 22, 2024
2f8e234
Add caching to get map data func by default through the memoise package
aleksanderbl29 Sep 22, 2024
9e3c664
Enable check for devel branch
aleksanderbl29 Sep 22, 2024
aeca7a4
Increment version number to 0.2.0
aleksanderbl29 Sep 22, 2024
5fa9a58
Revert "Enable check for devel branch"
aleksanderbl29 Sep 22, 2024
dd33980
Add more testing for map data
aleksanderbl29 Sep 22, 2024
aa488c5
importFrom tidyRSS properly
aleksanderbl29 Sep 24, 2024
8950938
load testthat on open
aleksanderbl29 Sep 24, 2024
c5cd5f9
Add proper whitespace in functions
aleksanderbl29 Sep 24, 2024
620ab3a
Specify ubuntu version
aleksanderbl29 Sep 27, 2024
0c4b5b0
Update httr2 10 v.1.0.5
aleksanderbl29 Sep 27, 2024
df8eddc
Add dynamic dots for get data
aleksanderbl29 Sep 27, 2024
012fe80
Add dynamic dots for get data
aleksanderbl29 Sep 27, 2024
316d789
fix duplicate
aleksanderbl29 Sep 27, 2024
c829023
Another way
aleksanderbl29 Sep 27, 2024
de9968e
remove dyn dots
aleksanderbl29 Sep 27, 2024
a1b69ab
Update cli messaging
aleksanderbl29 Sep 27, 2024
326e093
Sync dev branch (#39)
aleksanderbl29 Sep 27, 2024
79903b2
Update renv snapshot
aleksanderbl29 Oct 1, 2024
a144963
Add codemeta
aleksanderbl29 Oct 1, 2024
f7ed67f
update readme
aleksanderbl29 Oct 1, 2024
d8ef233
Specify branch for install github command
aleksanderbl29 Oct 1, 2024
289c3f2
Data has changed - Update snapshot
aleksanderbl29 Oct 4, 2024
11e73ad
update packages and upgrade renv
aleksanderbl29 Oct 4, 2024
5f59f74
Increment version number to 0.2.1
aleksanderbl29 Oct 4, 2024
b477415
Update renv snapshot
aleksanderbl29 Oct 5, 2024
8b394f6
ignore snapshot suggestions
aleksanderbl29 Oct 5, 2024
bbed1b0
Primarily update test data (#51)
aleksanderbl29 Oct 7, 2024
099ce29
fix duplication of postnumre
aleksanderbl29 Oct 7, 2024
1abb860
Fix another duplication and remove place types
aleksanderbl29 Oct 7, 2024
65601aa
Benchmark get map data timings and add cli info
aleksanderbl29 Oct 7, 2024
fcf2d8a
Update snapshots and fix broken test when removed sections
aleksanderbl29 Oct 7, 2024
8c45c2f
add place name types back in
aleksanderbl29 Oct 7, 2024
4ac6008
Add test to ensure that all available sections are appropriate (throw…
aleksanderbl29 Oct 8, 2024
93bec2d
Add test for sections and interim commit for snapshot update from ano…
aleksanderbl29 Oct 20, 2024
a75b7ee
Update snapshots pr 20 oct 2024
aleksanderbl29 Oct 20, 2024
b2f54ff
Merge branch 'section-check' into snapshot-update
aleksanderbl29 Oct 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
^\.pre-commit-config\.yaml$
^_pkgdown\.yml$
^benchmarking$
^codemeta\.json$
^cran-comments\.md$
^dawaR\.Rproj$
^doc$
Expand Down
1 change: 1 addition & 0 deletions .Rprofile
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ source("renv/activate.R")

if (interactive()) {
suppressMessages(require(devtools))
suppressMessages(require(testthat))
devtools::dev_sitrep()
}
2 changes: 2 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ repos:
- cli
- httr2
- sf
- memoise
- tidyRSS
# codemeta must be above use-tidy-description when both are used
# - id: codemeta-description-updated
Expand Down Expand Up @@ -63,6 +64,7 @@ repos:
(?x)^(
.Rprofile|
renv/.*|
benchmarking/.*|
)$
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
Expand Down
6 changes: 4 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: dawaR
Title: An API Wrapper Package for DAWA - The Danish Address Web API
Date: 2024-09-16
Version: 0.1.0
Version: 0.2.1
Authors@R:
person("Aleksander", "Bang-Larsen", , "[email protected]",
role = c("aut", "cre", "cph"),
Expand Down Expand Up @@ -30,8 +30,10 @@ Config/testthat/parallel: true
Depends:
R (>= 3.5.0)
Imports:
memoise (>= 2.0.0),
cli,
httr2,
sf,
tidyRSS
tidyRSS,
rlang
VignetteBuilder: knitr
3 changes: 3 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ export(get_data)
export(get_map_data)
export(reverse)
export(status_check)
importFrom(rlang,list2)
importFrom(rlang,splice)
importFrom(tidyRSS,tidyfeed)
11 changes: 11 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
# dawaR 0.2.1 (2024-10-6)

* Add more elaborate {cli} messaging for `get_map_data()`
* Including rough second or minute estimates for mostly used sections

# dawaR 0.2.0 (2024-09-22)

* Add caching for `get_map_data()`
* Enabled by default
* Adds new dependency `{memoise}`

# dawaR 0.1.0 (2024-09-16)

* Initial CRAN submission.
Expand Down
6 changes: 2 additions & 4 deletions R/available_sections.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ available_sections <- function(as_list = FALSE,
"navngivneveje",
"vejstykker",
"vejnavne",
"vejnavnpostnummerrelationer",
"supplerendebynavne2",
"postnumre"
"vejnavnpostnummerrelationer"
)

dagi_sections <- c(
Expand All @@ -61,7 +59,7 @@ available_sections <- function(as_list = FALSE,
stednavne <- c(
"steder",
"stednavne2",
"stednavntyper",
# "stednavntyper",
"bebyggelser"
)

Expand Down
7 changes: 4 additions & 3 deletions R/base_api.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ dawa <- function(section,
format = NULL,
verbose = TRUE,
cache = TRUE,
dry_run = FALSE) {
dry_run = FALSE,
func_params = list()) {
if (!is.null(format)) {
format <- match.arg(format, c(
"json", "jsonp", "ndjson",
Expand All @@ -53,7 +54,6 @@ dawa <- function(section,
}
}


params <- list(
...,
format = format
Expand All @@ -66,7 +66,8 @@ dawa <- function(section,
base_request <- httr2::request(base_url) |>
httr2::req_url_path_append(section) |>
httr2::req_url_path_append(append_to_url) |>
httr2::req_url_query(!!!params) |>
httr2::req_url_query(!!!params) |> # user provided query params
httr2::req_url_query(!!!func_params) |> # list of inputs from funcs
httr2::req_user_agent("dawaR (https://dawar.aleksanderbl.dk)")

if (cache == TRUE) {
Expand Down
7 changes: 5 additions & 2 deletions R/get_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,19 @@
#' x <- get_data("regioner")
#' head(x)
get_data <- function(section,
as_list = FALSE) {
as_list = FALSE, ...) {
if (!section %in% available_sections()) {
cli::cli_abort("You have provided section {.var {section}}.
It is not available through the api")
}

params <- rlang::list2(...)

response <- dawa(
section = section,
verbose = FALSE,
struktur = "flad"
struktur = "flad",
func_params = params
)

if (as_list == TRUE) {
Expand Down
53 changes: 49 additions & 4 deletions R/get_map_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,77 @@
#'
#' @param type Defines the type of map data to request from DAWA. Run
#' `available_sections(format = "geojson")` to see your options.
#' @param cache Boolean to determine whether or not to cache the api call and
#' the function output. Default is `TRUE`.
#'
#' @return Returns a `data.frame` object that contains polygons (or points) for
#' the section provided.
#'
#' @inheritParams dawa
#'
#' @export
#'
#' @examples
#' x <- get_map_data("regioner")
#' ggplot2::ggplot(x) +
#' ggplot2::geom_sf()
get_map_data <- function(type) {
get_map_data <- function(type, cache = TRUE, ...) {
params <- rlang::list2(...)

if (cache == TRUE) {
if (memoise::has_cache(get_map_data_w_cache)(type, params)) {
cli::cli_alert("Using cached response.
Change this behaviour by setting cache = FALSE")
}

get_map_data_w_cache(type = type, params = params)
} else if (cache == FALSE) {
get_map_data_nocache(type = type, cache = FALSE, params = params)
}
}

#' @importFrom rlang splice list2
get_map_data_w_cache <- memoise::memoise(function(type, params = list()) {
get_map_data_nocache(type = type, cache = TRUE, params = params)
})

#' @importFrom rlang splice list2
get_map_data_nocache <- function(type, cache = FALSE, params = list()) {
if (!type %in% available_sections(format = "geojson", verbose = FALSE)) {
cli::cli_abort("You have provided type {.var {type}}
which is not compatible with this function.")
}

check_sf_installation(verbose = FALSE)

cli::cli_progress_message("Fetching data from the API")
if (length(params) == 0) {
params <- NULL
}

time_info <- api_timings[type]

if (is.na(names(time_info))) {
time_info <- "a very long time"
}

cli::cli_alert(
"Getting data on {.var {type}}. This usually takes {time_info}."
)

cli::cli_progress_message(
"Fetching data from the API. This will take some time."
)

api_response <- dawa(
section = type,
format = "geojson",
verbose = FALSE
verbose = FALSE,
cache = cache,
func_params = params
)

cli::cli_progress_message("Reading data to `st`")
cli::cli_progress_message("Reading data to `st`.
This will also take some time.")

resp_st <- sf::st_read(
api_response,
Expand Down
2 changes: 2 additions & 0 deletions R/status_check.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#'
#' @return Returns a data frame object with the services and their statuses. Is
#' only returned if `return_df = TRUE`.
#'
#' @importFrom tidyRSS tidyfeed
#' @export
#'
#' @examples
Expand Down
18 changes: 18 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,21 @@ coordinate_type <- function(type) {
}
return(type_to_return)
}

api_timings <- list(
# this is from /benchmarking/timing.qmd and the accompanying
# /benchmarking/map_timings.rda
afstemningsomraader = "18.77s",
kommuner = "13.13s",
landsdele = "10.13s",
menighedsraadsafstemningsomraader = "25.9s",
opstillingskredse = "14.14s",
politikredse = "14.14s",
postnumre = "9.34s",
regioner = "10.24s",
retskredse = "11.44s",
sogne = "26.71s",
steder = "2.9m",
storkredse = "11.16s",
vlaglandsdele = "10.47s"
)
9 changes: 5 additions & 4 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ knitr::opts_chunk$set(
# dawaR <a href="https://dawar.aleksanderbl.dk/"><img src="man/figures/logo.png" align="right" height="139" alt="dawaR website" /></a>

<!-- badges: start -->
[![R-CMD-check](https://github.com/aleksanderbl29/dawaR/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/aleksanderbl29/dawaR/actions/workflows/R-CMD-check.yaml)
[![Codecov test coverage](https://codecov.io/gh/aleksanderbl29/dawaR/graph/badge.svg)](https://app.codecov.io/gh/aleksanderbl29/dawaR)
[![CRAN status](https://www.r-pkg.org/badges/version/dawaR)](https://CRAN.R-project.org/package=dawaR)
[![r-universe](https://aleksanderbl29.r-universe.dev/badges/dawaR)](https://aleksanderbl29.r-universe.dev/dawaR)
[![R-CMD-check](https://github.com/aleksanderbl29/dawaR/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/aleksanderbl29/dawaR/actions/workflows/R-CMD-check.yaml)
[![Codecov test coverage](https://codecov.io/gh/aleksanderbl29/dawaR/graph/badge.svg)](https://app.codecov.io/gh/aleksanderbl29/dawaR)
[![Project Status: Active – The project has reached a stable, usable state and is being actively developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active)
<!-- badges: end -->

The goal of `{dawaR}` is to make access to the Danish Web Address API convenient for many more users.
Expand Down Expand Up @@ -59,11 +60,11 @@ install.packages(
)
```

You can install the development version of `{dawaR}` from [GitHub](https://github.com/aleksanderbl29/dawaR) with:
You can install the latest development version of `{dawaR}` from [GitHub](https://github.com/aleksanderbl29/dawaR) with:

``` r
# install.packages("devtools")
devtools::install_github("aleksanderbl29/dawaR")
devtools::install_github("aleksanderbl29/dawaR@devel")
```

If you install the package in an environment configured with [`renv`](https://rstudio.github.io/renv/index.html) on MacOS, please consult `vignette("renv-issues")` to ensure that `get_map_data()` works as intended.
Expand Down
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@

<!-- badges: start -->

[![R-CMD-check](https://github.com/aleksanderbl29/dawaR/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/aleksanderbl29/dawaR/actions/workflows/R-CMD-check.yaml)
[![Codecov test
coverage](https://codecov.io/gh/aleksanderbl29/dawaR/graph/badge.svg)](https://app.codecov.io/gh/aleksanderbl29/dawaR)
[![CRAN
status](https://www.r-pkg.org/badges/version/dawaR)](https://CRAN.R-project.org/package=dawaR)
[![r-universe](https://aleksanderbl29.r-universe.dev/badges/dawaR)](https://aleksanderbl29.r-universe.dev/dawaR)
[![R-CMD-check](https://github.com/aleksanderbl29/dawaR/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/aleksanderbl29/dawaR/actions/workflows/R-CMD-check.yaml)
[![Codecov test
coverage](https://codecov.io/gh/aleksanderbl29/dawaR/graph/badge.svg)](https://app.codecov.io/gh/aleksanderbl29/dawaR)
[![Project Status: Active – The project has reached a stable, usable
state and is being actively
developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active)
<!-- badges: end -->

The goal of `{dawaR}` is to make access to the Danish Web Address API
Expand All @@ -30,12 +33,12 @@ install.packages(
)
```

You can install the development version of `{dawaR}` from
You can install the latest development version of `{dawaR}` from
[GitHub](https://github.com/aleksanderbl29/dawaR) with:

``` r
# install.packages("devtools")
devtools::install_github("aleksanderbl29/dawaR")
devtools::install_github("aleksanderbl29/dawaR@devel")
```

If you install the package in an environment configured with
Expand Down
2 changes: 2 additions & 0 deletions benchmarking/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.rda
*.rds
67 changes: 65 additions & 2 deletions benchmarking/map_data.R
Original file line number Diff line number Diff line change
@@ -1,11 +1,74 @@
manual_passthrough <- function() {
dawaR::dawa("regioner", format = "geojson", verbose = FALSE) |>
dawaR::dawa("sogne", format = "geojson", verbose = FALSE) |>
sf::read_sf() |>
sf::st_as_sf()
}

download_file <- function() {
temp_file <- tempfile()

download.file(
"https://api.dataforsyningen.dk/sogne?format=geojson",
temp_file
)

resp_st <- sf::st_read(
temp_file,
quiet = TRUE
)

map_data <- sf::st_as_sf(resp_st)

return(map_data)
}

temp_httr2 <- function() {
temp_file <- tempfile()

temp_file <- dawa(
section = "sogne",
format = "geojson",
verbose = FALSE
)

resp_st <- sf::st_read(
temp_file,
quiet = TRUE
)

map_data <- sf::st_as_sf(resp_st)

return(map_data)
}

manual_passthrough()
download_file()
temp_httr2()


bench::mark(
dawaR::get_map_data("sogne"),
manual_passthrough(),
download_file(),
temp_httr2(),
iterations = 10,
check = FALSE
)
bench::mark(
dawaR::get_map_data("sogne"),
manual_passthrough(),
download_file(),
temp_httr2(),
iterations = 3,
check = FALSE
)

microbenchmark::microbenchmark(
dawaR::get_map_data("regioner"),
dawaR::get_map_data("sogne"),
manual_passthrough(),
download_file(),
temp_httr2(),
times = 10
)

profvis::profvis(get_map_data("sogne"))
Loading
Loading