diff --git a/.Rbuildignore b/.Rbuildignore index 57f6c22..b7cfc08 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -9,3 +9,5 @@ ^docs$ ^README.Rmd$ ^.lintr$ +^doc$ +^Meta$ diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index bcdf126..542e9c9 100755 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -2,7 +2,7 @@ # Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help on: push: - branches: main + branches: [ main ] pull_request: workflow_dispatch: schedule: @@ -37,6 +37,7 @@ jobs: steps: - uses: actions/checkout@v4 + - uses: r-lib/actions/setup-pandoc@v2 - uses: r-lib/actions/setup-r@v2 @@ -44,15 +45,25 @@ jobs: r-version: ${{ matrix.config.r }} http-user-agent: ${{ matrix.config.http-user-agent }} use-public-rspm: true + extra-repositories: | + https://ropengov.r-universe.dev - uses: r-lib/actions/setup-r-dependencies@v2 with: cache-version: 3 extra-packages: | any::rcmdcheck + any::geodk + any::tidyverse needs: | check + # - name: Install package from r-universe + # run: | + # install.packages("remotes") + # remotes::install_github("rOpenGov/geodk") + # shell: Rscript {0} + - uses: r-lib/actions/check-r-package@v2 with: upload-snapshots: true diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml index d75b6c5..711054e 100644 --- a/.github/workflows/lint.yaml +++ b/.github/workflows/lint.yaml @@ -23,7 +23,7 @@ jobs: - uses: r-lib/actions/setup-r-dependencies@v2 with: cache-version: 2 - extra-packages: any::lintr, local::. + extra-packages: any::lintr, any::cyclocomp, local::. needs: lint - name: Lint diff --git a/.gitignore b/.gitignore index 7d41385..4bf787e 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,6 @@ read-and-delete-me test_script.R .DS_Store docs +inst/doc +/doc/ +/Meta/ diff --git a/.lintr b/.lintr index 42a3ead..12148bf 100644 --- a/.lintr +++ b/.lintr @@ -1,5 +1,9 @@ linters: linters_with_defaults( - cyclocomp_linter(complexity_limit = 17L)) + cyclocomp_linter(complexity_limit = 17L), + object_usage_linter = NULL, + return_linter = NULL) encoding: "UTF-8" exclusions: list( - "tests") + "tests", + "vignettes", + "R/s3_constructors.R") diff --git a/DESCRIPTION b/DESCRIPTION index b8ccf01..1d2d478 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Type: Package Package: dkstat Title: API connection to the StatBank from Statistics Denmark -Version: 0.0.0.9001 -Date: 2024-12-10 +Version: 0.0.0.9002 +Date: 2025-02-25 Authors@R: c( person("Aleksander", "Bang-Larsen", , "contact@aleksanderbl.dk", role = c("aut", "cre"), comment = c(ORCID = "0009-0007-7984-4650")), @@ -22,7 +22,10 @@ Imports: lubridate, stringr Suggests: - testthat + knitr, + rmarkdown, + testthat, + dplyr Encoding: UTF-8 Roxygen: list(markdown = TRUE) Config/testthat/edition: 3 @@ -31,5 +34,6 @@ RoxygenNote: 7.3.2 X-schema.org-isPartOf: http://ropengov.org/ X-schema.org-keywords: ropengov Depends: - R (>= 2.10) + R (>= 4.1) LazyData: true +VignetteBuilder: knitr diff --git a/NAMESPACE b/NAMESPACE index c2f0446..2edacaa 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -5,5 +5,6 @@ export(dst_get_data) export(dst_get_tables) export(dst_meta) export(dst_search) +importFrom(stats,na.omit) importFrom(utils,read.csv) importFrom(utils,read.csv2) diff --git a/R/determine_geo_properties.R b/R/determine_geo_properties.R new file mode 100644 index 0000000..c752f91 --- /dev/null +++ b/R/determine_geo_properties.R @@ -0,0 +1,36 @@ +# determine_geo_properties.R +# This file contains the logic to decide what kind of geographic information is +# included in a given dataset. The function is mainly used in +# `dst_get_data()` - Thus affecting `dst_get_all_data()` + +determine_geo_properties <- function(table, df) { + clnms <- colnames(df) + + meta <- dst_meta(table, lang = "da", geo = TRUE) + + if (is_geographic(meta)) { + chosen_constructor <- choose_geo_class(meta) + chosen_constructor(df) + } else { + df + } +} + +# Check if the metadata indicates a geographic variable +is_geographic <- function(meta) { + if (is.null(meta)) { + FALSE + } else if (!is.null(meta)) { + TRUE + } +} + +# Choose a class constructor +choose_geo_class <- function(meta) { + # Get the map variable + meta_class <- meta$variables$map + + # Paste class constructor name prefix with class name and get function + paste0("new_dkstat_", meta_class) |> + get() +} diff --git a/R/dst_get_all_data.R b/R/dst_get_all_data.R index 9db3892..d1cc23a 100644 --- a/R/dst_get_all_data.R +++ b/R/dst_get_all_data.R @@ -6,7 +6,8 @@ #' not need to specify anything other than a table name and you will be given #' the entire contents of the table in a nice long format. This is useful for #' you, if you would like to filter the table with e.g. `{dplyr}` functions or -#' save the entire table for archival. +#' save the entire table for archival. If the table is larger than the max +#' 1.000.000 cells, then you will have to use `dst_get_data()`. #' #' @export #' @inheritParams dst_get_data diff --git a/R/dst_get_data.R b/R/dst_get_data.R index d6049e7..5c38341 100644 --- a/R/dst_get_data.R +++ b/R/dst_get_data.R @@ -133,5 +133,7 @@ dst_get_data <- function(table, dst_data$TID <- dst_date_parse(dst_date = dst_data$TID) } - return(dst_data) + data <- determine_geo_properties(table, dst_data) + + return(data) } diff --git a/R/dst_meta.R b/R/dst_meta.R index 6a8a192..e72a72a 100644 --- a/R/dst_meta.R +++ b/R/dst_meta.R @@ -8,8 +8,10 @@ #' @param table The name of the table you want meta data for. #' @param ... Ignored. #' @param lang You can choose "en" for english or "da" for danish. +#' @param geo You can choose if the function should return the geographic +#' properties for the metadata. Mostly for internal use. #' @export -dst_meta <- function(table, ..., lang = "da") { +dst_meta <- function(table, ..., lang = "da", geo = FALSE) { ## Create and parse url dkstat_url <- paste0("http://api.statbank.dk/v1/tableinfo/", table, "?") dkstat_url <- httr::parse_url(url = dkstat_url) @@ -27,7 +29,11 @@ dst_meta <- function(table, ..., lang = "da") { ) ## Structure results - meta <- dst_meta_parse(meta, lang) + if (isFALSE(geo)) { + meta <- dst_meta_parse(meta, lang) + } else if (isTRUE(geo)) { + meta <- dst_meta_map(meta, lang) + } return(meta) } diff --git a/R/dst_meta_map.R b/R/dst_meta_map.R new file mode 100644 index 0000000..4f3d1a0 --- /dev/null +++ b/R/dst_meta_map.R @@ -0,0 +1,32 @@ +#' This function parses the JSON from the StatBank. +#' (http://www.statistikbanken.dk/statbank5a/ or http://www.dst.dk) and +#' retrieves the mapping information for all appropriate variables +#' +#' @description The function has been adapted from `dst_meta` to only retrieve +#' the geographic labels. +#' +#' +#' @inheritParams dst_meta_parse +#' @importFrom stats na.omit +#' @noRd +dst_meta_map <- function(meta, lang) { + # Get basic info on the table. + # The basics contains the table name/id and the short text of what is in the + # table + basics_names <- c("id", "text") + basics <- meta[names(meta) %in% basics_names] + + # Get the description of the variables. + # If map does not exist, we return a NULL + if (!"map" %in% colnames(meta[["variables"]])) { + return(NULL) + } + variables <- meta[["variables"]][, c("id", "text", "map")] |> + na.omit() + + # Return the data as a list. + return(list( + "basics" = basics, + "variables" = variables + )) +} diff --git a/R/s3_constructors.R b/R/s3_constructors.R new file mode 100644 index 0000000..534d01f --- /dev/null +++ b/R/s3_constructors.R @@ -0,0 +1,102 @@ +# s3_constructors.R +# This file defines all the s3 constructors needed for the appropriate dispatch +# of geographic matching in `{geodk}` (or other packages that might benefit from +# knowing the geographic type). The class is assigned "after the fact", as +# Wickham calls it, ensuring that the usual behaviour of a data.frame is +# preserved for all the functions that don't know about these special classes. + +new_dkstat_KOMGRP <- function(x) { + stopifnot(is.data.frame(x)) + class(x) <- c("dkstat_KOMGRP", class(x)) + return(x) +} + +new_dkstat_kom_omraade <- function(x) { + stopifnot(is.data.frame(x)) + class(x) <- c("dkstat_kom_omraade", class(x)) + return(x) +} + +new_dkstat_Denmark_municipality_07 <- function(x) { + stopifnot(is.data.frame(x)) + class(x) <- c("dkstat_Denmark_municipality_07", class(x)) + return(x) +} + +new_dkstat_Verden_dk2 <- function(x) { + stopifnot(is.data.frame(x)) + class(x) <- c("dkstat_Verden_dk2", class(x)) + return(x) +} + +new_dkstat_denmark_cities_19 <- function(x) { + stopifnot(is.data.frame(x)) + class(x) <- c("dkstat_denmark_cities_19", class(x)) + return(x) +} + +new_dkstat_denmark_parish_23_4c <- function(x) { + stopifnot(is.data.frame(x)) + class(x) <- c("dkstat_denmark_parish_23_4c", class(x)) + return(x) +} + +new_dkstat_denmark_municipalitygroups_24 <- function(x) { + stopifnot(is.data.frame(x)) + class(x) <- c("dkstat_denmark_municipalitygroups_24", class(x)) + return(x) +} + +new_dkstat_Denmark_region_07 <- function(x) { + stopifnot(is.data.frame(x)) + class(x) <- c("dkstat_Denmark_region_07", class(x)) + return(x) +} + +new_dkstat_Denmark_rural_07 <- function(x) { + stopifnot(is.data.frame(x)) + class(x) <- c("dkstat_Denmark_rural_07", class(x)) + return(x) +} + +new_dkstat_denmark_multimember_constituency_23 <- function(x) { + stopifnot(is.data.frame(x)) + class(x) <- c("dkstat_denmark_multimember_constituency_23", class(x)) + return(x) +} + +new_dkstat_denmark_deanary_23 <- function(x) { + stopifnot(is.data.frame(x)) + class(x) <- c("dkstat_denmark_deanary_23", class(x)) + return(x) +} + +new_dkstat_europe_dk <- function(x) { + stopifnot(is.data.frame(x)) + class(x) <- c("dkstat_europe_dk", class(x)) + return(x) +} + +new_dkstat_Verden_dk <- function(x) { + stopifnot(is.data.frame(x)) + class(x) <- c("dkstat_Verden_dk", class(x)) + return(x) +} + +new_dkstat_Europa_DK3 <- function(x) { + stopifnot(is.data.frame(x)) + class(x) <- c("dkstat_Europa_DK3", class(x)) + return(x) +} + +new_dkstat_Denmark_county <- function(x) { + stopifnot(is.data.frame(x)) + class(x) <- c("dkstat_Denmark_county", class(x)) + return(x) +} + +new_dkstat_Verden_dk4 <- function(x) { + stopifnot(is.data.frame(x)) + class(x) <- c("dkstat_Verden_dk4", class(x)) + return(x) +} diff --git a/data-raw/dkstat_groups.R b/data-raw/dkstat_groups.R new file mode 100644 index 0000000..dc0a1bf --- /dev/null +++ b/data-raw/dkstat_groups.R @@ -0,0 +1,169 @@ +# dkstat_groups.R +# This file is found in +# https://github.com/rOpenGov/dkstat/blob/main/data-raw/dkstat_groups.R and +# https://github.com/rOpenGov/geodk/blob/main/data-raw/dkstat_groups.R. If you +# change anything in either file, please remember to change in both places. + +## Municipality groups - KOMGRP +create_groups <- function(x) { + + levels <- x |> + dplyr::filter(NIVEAU == 1) |> + unique() |> + dplyr::pull(name) + + id <- 0 + groups <- numeric(nrow(x)) + + for (i in seq_len(x)) { + if (x$NIVEAU[i] == 1) { + id <- id + 1 + } + + groups[i] <- id + } + + x$group <- groups + x$level <- levels[groups] + return(x) +} + +# I have contacted the consultant in charge of the classification and requested +# a download-link / api-access to not have to distribute the csv-file alongside +# the package source code. +# https://www.dst.dk/da/Statistik/dokumentation/nomenklaturer/kommunegrupper +komgrp <- readr::read_csv2("data-raw/komgrp.csv") |> + dplyr::select(KODE, NIVEAU, TITEL) |> + dplyr::mutate( + name = paste(KODE, TITEL) + ) |> + create_groups() |> + dplyr::group_by(level) |> + dplyr::filter(NIVEAU == 2) |> + dplyr::summarise( + list = list({ + values <- TITEL + names(values) <- paste(KODE, TITEL, sep = " ") + as.list(values) + }) + ) |> + tibble::deframe() + +usethis::use_data(komgrp, compress = "xz", overwrite = TRUE, internal = TRUE) + + +# Municipality groups with "Hele landet" as well +kom_omraade <- c( + "000 Hele landet", + "1 Hovedstadskommuner", + "2 Storbykommuner", + "3 Provinsbykommuner", + "4 Oplandskommuner", + "5 Landkommuner", + "101 København", + "147 Frederiksberg", + "155 Dragør", + "185 Tårnby", + "165 Albertslund", + "151 Ballerup", + "153 Brøndby", + "157 Gentofte", + "159 Gladsaxe", + "161 Glostrup", + "163 Herlev", + "167 Hvidovre", + "169 Høje-Taastrup", + "183 Ishøj", + "173 Lyngby-Taarbæk", + "175 Rødovre", + "187 Vallensbæk", + "201 Allerød", + "240 Egedal", + "210 Fredensborg", + "250 Frederikssund", + "190 Furesø", + "270 Gribskov", + "260 Halsnæs", + "217 Helsingør", + "219 Hillerød", + "223 Hørsholm", + "230 Rudersdal", + "400 Bornholm", + "411 Christiansø", + "253 Greve", + "259 Køge", + "350 Lejre", + "265 Roskilde", + "269 Solrød", + "320 Faxe", + "376 Guldborgsund", + "316 Holbæk", + "326 Kalundborg", + "360 Lolland", + "370 Næstved", + "306 Odsherred", + "329 Ringsted", + "330 Slagelse", + "340 Sorø", + "336 Stevns", + "390 Vordingborg", + "420 Assens", + "430 Faaborg-Midtfyn", + "440 Kerteminde", + "482 Langeland", + "410 Middelfart", + "480 Nordfyns", + "450 Nyborg", + "461 Odense", + "479 Svendborg", + "492 Ærø", + "530 Billund", + "561 Esbjerg", + "563 Fanø", + "607 Fredericia", + "510 Haderslev", + "621 Kolding", + "540 Sønderborg", + "550 Tønder", + "573 Varde", + "575 Vejen", + "630 Vejle", + "580 Aabenraa", + "710 Favrskov", + "766 Hedensted", + "615 Horsens", + "707 Norddjurs", + "727 Odder", + "730 Randers", + "741 Samsø", + "740 Silkeborg", + "746 Skanderborg", + "706 Syddjurs", + "751 Aarhus", + "657 Herning", + "661 Holstebro", + "756 Ikast-Brande", + "665 Lemvig", + "760 Ringkøbing-Skjern", + "779 Skive", + "671 Struer", + "791 Viborg", + "810 Brønderslev", + "813 Frederikshavn", + "860 Hjørring", + "849 Jammerbugt", + "825 Læsø", + "846 Mariagerfjord", + "773 Morsø", + "840 Rebild", + "787 Thisted", + "820 Vesthimmerlands", + "851 Aalborg" +) + +usethis::use_data( + kom_omraade, + compress = "xz", + overwrite = TRUE, + internal = TRUE +) diff --git a/data-raw/dst_map.R b/data-raw/dst_map.R new file mode 100644 index 0000000..d4a5aa0 --- /dev/null +++ b/data-raw/dst_map.R @@ -0,0 +1,62 @@ +# dst_map.R +# This file is created to get all the map-levels provided by the API. They are +# used for the integration with `{geodk}` + +# Load package +devtools::load_all(".") + +# Define custom function to get metadata (this is extracted from dst_meta()) +get_meta <- function(table, lang = "da") { + dkstat_url <- paste0("http://api.statbank.dk/v1/tableinfo/", table, "?") + dkstat_url <- httr::parse_url(url = dkstat_url) + + ## Insert query + dkstat_url$query <- list("lang" = lang, "format" = "JSON") + + ## Get data + meta <- httr::GET(url = dkstat_url) + + ## Parse from JSON + meta <- jsonlite::fromJSON( + txt = httr::content(meta, as = "text"), + simplifyDataFrame = TRUE + ) + + return(meta) +} + +# Get all tables +tbls <- dst_get_tables()$id + +# Define empty map list +maps <- list() + +# Loop for getting map label for each table +for (table in tbls) { + cat("Processing:", table, "\n") + x <- get_meta(table) |> + dst_meta_map() + if (!"map" %in% colnames(x$variables)) { + cat(table, "does not have a geographic label", "\n") + } else { + cat(table, "has", x$variables$map, "\n") + maps[table] <- x$variables$map + print(maps) + } +} + +# Get a unique list of all the levels +map_levels <- maps |> + unname() |> + unlist() |> + unique() + +# Get a flat list +flat <- unlist(maps) + +# Extract the name-value pairs for the first observation of each map-type +map_types <- maps[match(map_levels, flat)] + + +muni <- flat[flat %in% map_levels[1]] |> + names() diff --git a/data-raw/komgrp.csv b/data-raw/komgrp.csv new file mode 100644 index 0000000..9c50d4a --- /dev/null +++ b/data-raw/komgrp.csv @@ -0,0 +1,104 @@ +SEKVENS;KODE;NIVEAU;TITEL;GENERELLE_NOTER;INKLUDERER;INKLUDERER_OGSÅ;EKSKLUDERER;PARAGRAF;MÅLEENHED +1;"1";1;Hovedstadskommuner;;;;;; +2;"101";2;København;;;;;; +3;"147";2;Frederiksberg;;;;;; +4;"151";2;Ballerup;;;;;; +5;"153";2;Brøndby;;;;;; +6;"155";2;Dragør;;;;;; +7;"157";2;Gentofte;;;;;; +8;"159";2;Gladsaxe;;;;;; +9;"161";2;Glostrup;;;;;; +10;"163";2;Herlev;;;;;; +11;"165";2;Albertslund;;;;;; +12;"167";2;Hvidovre;;;;;; +13;"169";2;Høje-Taastrup;;;;;; +14;"173";2;Lyngby-Taarbæk;;;;;; +15;"175";2;Rødovre;;;;;; +16;"183";2;Ishøj;;;;;; +17;"185";2;Tårnby;;;;;; +18;"187";2;Vallensbæk;;;;;; +19;"190";2;Furesø;;;;;; +20;"201";2;Allerød;;;;;; +21;"223";2;Hørsholm;;;;;; +22;"230";2;Rudersdal;;;;;; +23;"240";2;Egedal;;;;;; +24;"253";2;Greve;;;;;; +25;"269";2;Solrød;;;;;; +26;"2";1;Storbykommuner;;;;;; +27;"461";2;Odense;;;;;; +28;"751";2;Aarhus;;;;;; +29;"851";2;Aalborg;;;;;; +30;"3";1;Provinsbykommuner;;;;;; +31;"217";2;Helsingør;;;;;; +32;"219";2;Hillerød;;;;;; +33;"259";2;Køge;;;;;; +34;"265";2;Roskilde;;;;;; +35;"330";2;Slagelse;;;;;; +36;"370";2;Næstved;;;;;; +37;"561";2;Esbjerg;;;;;; +38;"607";2;Fredericia;;;;;; +39;"615";2;Horsens;;;;;; +40;"621";2;Kolding;;;;;; +41;"630";2;Vejle;;;;;; +42;"657";2;Herning;;;;;; +43;"661";2;Holstebro;;;;;; +44;"730";2;Randers;;;;;; +45;"740";2;Silkeborg;;;;;; +46;"791";2;Viborg;;;;;; +47;"4";1;Oplandskommuner;;;;;; +48;"210";2;Fredensborg;;;;;; +49;"250";2;Frederikssund;;;;;; +50;"260";2;Halsnæs;;;;;; +51;"270";2;Gribskov;;;;;; +52;"316";2;Holbæk;;;;;; +53;"320";2;Faxe;;;;;; +54;"329";2;Ringsted;;;;;; +55;"336";2;Stevns;;;;;; +56;"340";2;Sorø;;;;;; +57;"350";2;Lejre;;;;;; +58;"410";2;Middelfart;;;;;; +59;"420";2;Assens;;;;;; +60;"430";2;Faaborg-Midtfyn;;;;;; +61;"440";2;Kerteminde;;;;;; +62;"450";2;Nyborg;;;;;; +63;"480";2;Nordfyns;;;;;; +64;"575";2;Vejen;;;;;; +65;"706";2;Syddjurs;;;;;; +66;"710";2;Favrskov;;;;;; +67;"727";2;Odder;;;;;; +68;"746";2;Skanderborg;;;;;; +69;"756";2;Ikast-Brande;;;;;; +70;"766";2;Hedensted;;;;;; +71;"840";2;Rebild;;;;;; +72;"5";1;Landkommuner;;;;;; +73;"306";2;Odsherred;;;;;; +74;"326";2;Kalundborg;;;;;; +75;"360";2;Lolland;;;;;; +76;"376";2;Guldborgsund;;;;;; +77;"390";2;Vordingborg;;;;;; +78;"400";2;Bornholm;;;;;; +79;"479";2;Svendborg;;;;;; +80;"482";2;Langeland;;;;;; +81;"492";2;Ærø;;;;;; +82;"510";2;Haderslev;;;;;; +83;"530";2;Billund;;;;;; +84;"540";2;Sønderborg;;;;;; +85;"550";2;Tønder;;;;;; +86;"563";2;Fanø;;;;;; +87;"573";2;Varde;;;;;; +88;"580";2;Aabenraa;;;;;; +89;"665";2;Lemvig;;;;;; +90;"671";2;Struer;;;;;; +91;"707";2;Norddjurs;;;;;; +92;"741";2;Samsø;;;;;; +93;"760";2;Ringkøbing-Skjern;;;;;; +94;"773";2;Morsø;;;;;; +95;"779";2;Skive;;;;;; +96;"787";2;Thisted;;;;;; +97;"810";2;Brønderslev;;;;;; +98;"813";2;Frederikshavn;;;;;; +99;"820";2;Vesthimmerlands;;;;;; +100;"825";2;Læsø;;;;;; +101;"846";2;Mariagerfjord;;;;;; +102;"849";2;Jammerbugt;;;;;; +103;"860";2;Hjørring;;;;;; diff --git a/data/tables.rda b/data/tables.rda index e2f4dc1..a0af0e7 100644 Binary files a/data/tables.rda and b/data/tables.rda differ diff --git a/dkstat.Rproj b/dkstat.Rproj index 9539a17..39b135b 100644 --- a/dkstat.Rproj +++ b/dkstat.Rproj @@ -1,5 +1,5 @@ Version: 1.0 -ProjectId: 0fa5e426-8c7c-454b-b5f9-7d4f91b882c1 +ProjectId: 2f8c1cc5-d2d5-4418-86e7-a3dc41bb0046 RestoreWorkspace: Default SaveWorkspace: Default diff --git a/man/dst_get_all_data.Rd b/man/dst_get_all_data.Rd index 82e926e..83a8ad6 100644 --- a/man/dst_get_all_data.Rd +++ b/man/dst_get_all_data.Rd @@ -21,7 +21,8 @@ provides all the query parameters on the user's behalf. You, as a user, do not need to specify anything other than a table name and you will be given the entire contents of the table in a nice long format. This is useful for you, if you would like to filter the table with e.g. \code{{dplyr}} functions or -save the entire table for archival. +save the entire table for archival. If the table is larger than the max +1.000.000 cells, then you will have to use \code{dst_get_data()}. } \seealso{ Other Data retrival functions: diff --git a/man/dst_meta.Rd b/man/dst_meta.Rd index ac9cce9..12b8683 100644 --- a/man/dst_meta.Rd +++ b/man/dst_meta.Rd @@ -6,7 +6,7 @@ Statistics Denmark. (http://www.statistikbanken.dk/statbank5a/ or http://www.dst.dk)} \usage{ -dst_meta(table, ..., lang = "da") +dst_meta(table, ..., lang = "da", geo = FALSE) } \arguments{ \item{table}{The name of the table you want meta data for.} @@ -14,6 +14,9 @@ dst_meta(table, ..., lang = "da") \item{...}{Ignored.} \item{lang}{You can choose "en" for english or "da" for danish.} + +\item{geo}{You can choose if the function should return the geographic +properties for the metadata. Mostly for internal use.} } \description{ This function POSTs a request for meta data on a table from Statistics diff --git a/renv.lock b/renv.lock index 7967920..8662fa9 100644 --- a/renv.lock +++ b/renv.lock @@ -21,6 +21,50 @@ ] }, "Packages": { + "BH": { + "Package": "BH", + "Version": "1.87.0-1", + "Source": "Repository", + "Repository": "CRAN", + "Hash": "468d9a03ba57f22ebde50060fd13ba9f" + }, + "DBI": { + "Package": "DBI", + "Version": "1.2.3", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "methods" + ], + "Hash": "065ae649b05f1ff66bb0c793107508f5" + }, + "KernSmooth": { + "Package": "KernSmooth", + "Version": "2.23-24", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "stats" + ], + "Hash": "9f33a1ee37bbe8919eb2ec4b9f2473a5" + }, + "MASS": { + "Package": "MASS", + "Version": "7.3-61", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "grDevices", + "graphics", + "methods", + "stats", + "utils" + ], + "Hash": "0cafd6f0500e5deba33be22c46bf6055" + }, "Matrix": { "Package": "Matrix", "Version": "1.7-1", @@ -48,6 +92,16 @@ ], "Hash": "470851b6d5d0ac559e9d01bb352b4021" }, + "RColorBrewer": { + "Package": "RColorBrewer", + "Version": "1.1-3", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R" + ], + "Hash": "45f0398006e83a5b10b72a90663d8d8c" + }, "Rcpp": { "Package": "Rcpp", "Version": "1.0.14", @@ -66,6 +120,18 @@ "Repository": "CRAN", "Hash": "46da3912f69e3e6258a033802c4af32e" }, + "anytime": { + "Package": "anytime", + "Version": "0.3.11", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "BH", + "R", + "Rcpp" + ], + "Hash": "a1db66ce27bcfb58cb67ad4e04d48b79" + }, "askpass": { "Package": "askpass", "Version": "1.2.1", @@ -98,6 +164,16 @@ ], "Hash": "5d0f7d92f3b12c79530eba0f60456e76" }, + "backports": { + "Package": "backports", + "Version": "1.5.0", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R" + ], + "Hash": "e1e1b9d75c37401117b636b7ae50827a" + }, "base64enc": { "Package": "base64enc", "Version": "0.1-3", @@ -108,6 +184,43 @@ ], "Hash": "543776ae6848fde2f48ff3816d0628bc" }, + "bit": { + "Package": "bit", + "Version": "4.5.0.1", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R" + ], + "Hash": "f89f074e0e49bf1dbe3eba0a15a91476" + }, + "bit64": { + "Package": "bit64", + "Version": "4.6.0-1", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "bit", + "graphics", + "methods", + "stats", + "utils" + ], + "Hash": "4f572fbc586294afff277db583b9060f" + }, + "blob": { + "Package": "blob", + "Version": "1.2.4", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "methods", + "rlang", + "vctrs" + ], + "Hash": "40415719b5a479b87949f3aa0aee737c" + }, "brew": { "Package": "brew", "Version": "1.0-10", @@ -125,6 +238,26 @@ ], "Hash": "c1ee497a6d999947c2c224ae46799b1a" }, + "broom": { + "Package": "broom", + "Version": "1.0.7", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "backports", + "dplyr", + "generics", + "glue", + "lifecycle", + "purrr", + "rlang", + "stringr", + "tibble", + "tidyr" + ], + "Hash": "8fcc818f3b9887aebaf206f141437cc9" + }, "bslib": { "Package": "bslib", "Version": "0.8.0", @@ -171,6 +304,47 @@ ], "Hash": "d7e13f49c19103ece9e58ad2d83a7354" }, + "cellranger": { + "Package": "cellranger", + "Version": "1.1.0", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "rematch", + "tibble" + ], + "Hash": "f61dbaec772ccd2e17705c1e872e9e7c" + }, + "class": { + "Package": "class", + "Version": "7.3-22", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "MASS", + "R", + "stats", + "utils" + ], + "Hash": "f91f6b29f38b8c280f2b9477787d4bb2" + }, + "classInt": { + "Package": "classInt", + "Version": "0.4-11", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "KernSmooth", + "R", + "class", + "e1071", + "grDevices", + "graphics", + "stats" + ], + "Hash": "f2af70314a63d7f025ae668f08bd933a" + }, "cli": { "Package": "cli", "Version": "3.6.3", @@ -199,6 +373,20 @@ "Repository": "CRAN", "Hash": "96c01552bfd5661b9bbdefbc762f4bcd" }, + "colorspace": { + "Package": "colorspace", + "Version": "2.1-1", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "grDevices", + "graphics", + "methods", + "stats" + ], + "Hash": "d954cb1c57e8d8b756165d7ba18aa55a" + }, "commonmark": { "Package": "commonmark", "Version": "1.9.2", @@ -206,6 +394,19 @@ "Repository": "CRAN", "Hash": "14eb0596f987c71535d07c3aff814742" }, + "conflicted": { + "Package": "conflicted", + "Version": "1.2.0", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "cli", + "memoise", + "rlang" + ], + "Hash": "bb097fccb22d156624fd07cd2894ddb6" + }, "cpp11": { "Package": "cpp11", "Version": "0.5.1", @@ -252,6 +453,66 @@ ], "Hash": "8dd23d308c751efdf675124aad4bf5d7" }, + "data.table": { + "Package": "data.table", + "Version": "1.16.4", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "methods" + ], + "Hash": "38bbf05fc2503143db4c734a7e5cab66" + }, + "dawaR": { + "Package": "dawaR", + "Version": "0.2.7.9000", + "Source": "Repository", + "Repository": "https://aleksanderbl29.r-universe.dev", + "RemoteUrl": "https://github.com/aleksanderbl29/dawaR", + "RemoteRef": "universe-release", + "RemoteSha": "c81e0444a57c82fbc5f41baa6b10713c6bcaa83f", + "Requirements": [ + "R", + "cli", + "curl", + "httr2", + "memoise", + "rlang", + "sf", + "tidyRSS", + "utils" + ], + "Hash": "92c45684111c462b713c792fa9e3265e" + }, + "dbplyr": { + "Package": "dbplyr", + "Version": "2.5.0", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "DBI", + "R", + "R6", + "blob", + "cli", + "dplyr", + "glue", + "lifecycle", + "magrittr", + "methods", + "pillar", + "purrr", + "rlang", + "tibble", + "tidyr", + "tidyselect", + "utils", + "vctrs", + "withr" + ], + "Hash": "39b2e002522bfd258039ee4e889e0fd1" + }, "desc": { "Package": "desc", "Version": "1.4.3", @@ -368,6 +629,41 @@ ], "Hash": "fedd9d00c2944ff00a0e2696ccf048ec" }, + "dtplyr": { + "Package": "dtplyr", + "Version": "1.3.1", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "cli", + "data.table", + "dplyr", + "glue", + "lifecycle", + "rlang", + "tibble", + "tidyselect", + "vctrs" + ], + "Hash": "54ed3ea01b11e81a86544faaecfef8e2" + }, + "e1071": { + "Package": "e1071", + "Version": "1.7-16", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "class", + "grDevices", + "graphics", + "methods", + "proxy", + "stats", + "utils" + ], + "Hash": "27a09ca40266a1066d62ef5402dd51d6" + }, "ellipsis": { "Package": "ellipsis", "Version": "0.3.2", @@ -401,6 +697,13 @@ ], "Hash": "962174cf2aeb5b9eea581522286a911f" }, + "farver": { + "Package": "farver", + "Version": "2.1.2", + "Source": "Repository", + "Repository": "CRAN", + "Hash": "680887028577f3fa2a81e410ed0d6e42" + }, "fastmap": { "Package": "fastmap", "Version": "1.2.0", @@ -420,6 +723,22 @@ ], "Hash": "bd1297f9b5b1fc1372d19e2c4cd82215" }, + "forcats": { + "Package": "forcats", + "Version": "1.0.0", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "cli", + "glue", + "lifecycle", + "magrittr", + "rlang", + "tibble" + ], + "Hash": "1a0a9a3d5083d0d573c4214576f1e690" + }, "fs": { "Package": "fs", "Version": "1.6.5", @@ -431,6 +750,28 @@ ], "Hash": "7f48af39fa27711ea5fbd183b399920d" }, + "gargle": { + "Package": "gargle", + "Version": "1.5.2", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "cli", + "fs", + "glue", + "httr", + "jsonlite", + "lifecycle", + "openssl", + "rappdirs", + "rlang", + "stats", + "utils", + "withr" + ], + "Hash": "fc0b272e5847c58cd5da9b20eedbd026" + }, "generics": { "Package": "generics", "Version": "0.1.3", @@ -442,6 +783,20 @@ ], "Hash": "15e9634c0fcd294799e9b2e929ed1b86" }, + "geodk": { + "Package": "geodk", + "Version": "0.0.0.9000", + "Source": "Repository", + "Repository": "rOpenGov", + "Requirements": [ + "R", + "dawaR", + "dplyr", + "ggplot2", + "rlang" + ], + "Hash": "a209fab6f9197c53a7a6979ab2945173" + }, "gert": { "Package": "gert", "Version": "2.1.4", @@ -457,6 +812,31 @@ ], "Hash": "ae855ad6d7be20dd7b05d43d25700398" }, + "ggplot2": { + "Package": "ggplot2", + "Version": "3.5.1", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "MASS", + "R", + "cli", + "glue", + "grDevices", + "grid", + "gtable", + "isoband", + "lifecycle", + "mgcv", + "rlang", + "scales", + "stats", + "tibble", + "vctrs", + "withr" + ], + "Hash": "44c6a2f8202d5b7e878ea274b1092426" + }, "gh": { "Package": "gh", "Version": "1.4.1", @@ -496,6 +876,96 @@ ], "Hash": "5899f1eaa825580172bb56c08266f37c" }, + "googledrive": { + "Package": "googledrive", + "Version": "2.1.1", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "cli", + "gargle", + "glue", + "httr", + "jsonlite", + "lifecycle", + "magrittr", + "pillar", + "purrr", + "rlang", + "tibble", + "utils", + "uuid", + "vctrs", + "withr" + ], + "Hash": "e99641edef03e2a5e87f0a0b1fcc97f4" + }, + "googlesheets4": { + "Package": "googlesheets4", + "Version": "1.1.1", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "cellranger", + "cli", + "curl", + "gargle", + "glue", + "googledrive", + "httr", + "ids", + "lifecycle", + "magrittr", + "methods", + "purrr", + "rematch2", + "rlang", + "tibble", + "utils", + "vctrs", + "withr" + ], + "Hash": "d6db1667059d027da730decdc214b959" + }, + "gtable": { + "Package": "gtable", + "Version": "0.3.6", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "cli", + "glue", + "grid", + "lifecycle", + "rlang", + "stats" + ], + "Hash": "de949855009e2d4d0e52a844e30617ae" + }, + "haven": { + "Package": "haven", + "Version": "2.5.4", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "cli", + "cpp11", + "forcats", + "hms", + "lifecycle", + "methods", + "readr", + "rlang", + "tibble", + "tidyselect", + "vctrs" + ], + "Hash": "9171f898db9d9c4c1b2c745adc2c1ef1" + }, "highr": { "Package": "highr", "Version": "0.11", @@ -507,6 +977,20 @@ ], "Hash": "d65ba49117ca223614f71b60d85b8ab7" }, + "hms": { + "Package": "hms", + "Version": "1.1.3", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "lifecycle", + "methods", + "pkgconfig", + "rlang", + "vctrs" + ], + "Hash": "b59377caa7ed00fa41808342002138f9" + }, "htmltools": { "Package": "htmltools", "Version": "0.5.8.1", @@ -589,6 +1073,17 @@ ], "Hash": "0f14199bbd820a9fca398f2df40994f1" }, + "ids": { + "Package": "ids", + "Version": "1.0.1", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "openssl", + "uuid" + ], + "Hash": "99df65cfef20e525ed38c3d2577f7190" + }, "ini": { "Package": "ini", "Version": "0.3.1", @@ -596,6 +1091,17 @@ "Repository": "CRAN", "Hash": "6154ec2223172bce8162d4153cda21f7" }, + "isoband": { + "Package": "isoband", + "Version": "0.2.7", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "grid", + "utils" + ], + "Hash": "0080607b4a1a7b28979aecef976d8bc2" + }, "janeaustenr": { "Package": "janeaustenr", "Version": "1.0.0", @@ -642,6 +1148,17 @@ ], "Hash": "9fcb189926d93c636dea94fbe4f44480" }, + "labeling": { + "Package": "labeling", + "Version": "0.4.3", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "graphics", + "stats" + ], + "Hash": "b64ec208ac5bc1852b285f665d6368b3" + }, "later": { "Package": "later", "Version": "1.4.1", @@ -713,29 +1230,89 @@ "cachem", "rlang" ], - "Hash": "e2817ccf4a065c5d9d7f2cfbe7c1d78c" + "Hash": "e2817ccf4a065c5d9d7f2cfbe7c1d78c" + }, + "mgcv": { + "Package": "mgcv", + "Version": "1.9-1", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "Matrix", + "R", + "graphics", + "methods", + "nlme", + "splines", + "stats", + "utils" + ], + "Hash": "110ee9d83b496279960e162ac97764ce" + }, + "mime": { + "Package": "mime", + "Version": "0.12", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "tools" + ], + "Hash": "18e9c28c1d3ca1560ce30658b22ce104" + }, + "miniUI": { + "Package": "miniUI", + "Version": "0.1.1.1", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "htmltools", + "shiny", + "utils" + ], + "Hash": "fec5f52652d60615fdb3957b3d74324a" + }, + "modelr": { + "Package": "modelr", + "Version": "0.1.11", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "broom", + "magrittr", + "purrr", + "rlang", + "tibble", + "tidyr", + "tidyselect", + "vctrs" + ], + "Hash": "4f50122dc256b1b6996a4703fecea821" }, - "mime": { - "Package": "mime", - "Version": "0.12", + "munsell": { + "Package": "munsell", + "Version": "0.5.1", "Source": "Repository", "Repository": "CRAN", "Requirements": [ - "tools" + "colorspace", + "methods" ], - "Hash": "18e9c28c1d3ca1560ce30658b22ce104" + "Hash": "4fd8900853b746af55b81fda99da7695" }, - "miniUI": { - "Package": "miniUI", - "Version": "0.1.1.1", + "nlme": { + "Package": "nlme", + "Version": "3.1-166", "Source": "Repository", "Repository": "CRAN", "Requirements": [ - "htmltools", - "shiny", + "R", + "graphics", + "lattice", + "stats", "utils" ], - "Hash": "fec5f52652d60615fdb3957b3d74324a" + "Hash": "ccbb8846be320b627e6aa2b4616a2ded" }, "openssl": { "Package": "openssl", @@ -883,6 +1460,20 @@ ], "Hash": "bffa126bf92987e677c12cfb5651fc1d" }, + "progress": { + "Package": "progress", + "Version": "1.2.3", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "R6", + "crayon", + "hms", + "prettyunits" + ], + "Hash": "f4625e061cb2865f111b47ff163a5ca6" + }, "promises": { "Package": "promises", "Version": "1.3.2", @@ -899,6 +1490,18 @@ ], "Hash": "c84fd4f75ea1f5434735e08b7f50fbca" }, + "proxy": { + "Package": "proxy", + "Version": "0.4-27", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "stats", + "utils" + ], + "Hash": "e0ef355c12942cf7a6b91a6cfaea8b3e" + }, "ps": { "Package": "ps", "Version": "1.8.1", @@ -968,6 +1571,61 @@ ], "Hash": "8f25ebe2ec38b1f2aef3b0d2ef76f6c4" }, + "readr": { + "Package": "readr", + "Version": "2.1.5", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "R6", + "cli", + "clipr", + "cpp11", + "crayon", + "hms", + "lifecycle", + "methods", + "rlang", + "tibble", + "tzdb", + "utils", + "vroom" + ], + "Hash": "9de96463d2117f6ac49980577939dfb3" + }, + "readxl": { + "Package": "readxl", + "Version": "1.4.3", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "cellranger", + "cpp11", + "progress", + "tibble", + "utils" + ], + "Hash": "8cf9c239b96df1bbb133b74aef77ad0a" + }, + "rematch": { + "Package": "rematch", + "Version": "2.0.0", + "Source": "Repository", + "Repository": "CRAN", + "Hash": "cbff1b666c6fa6d21202f07e2318d4f1" + }, + "rematch2": { + "Package": "rematch2", + "Version": "2.1.2", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "tibble" + ], + "Hash": "76c9e04c712a05848ae7a23d2f170a40" + }, "remotes": { "Package": "remotes", "Version": "2.5.0", @@ -992,6 +1650,28 @@ ], "Hash": "47623f66b4e80b3b0587bc5d7b309888" }, + "reprex": { + "Package": "reprex", + "Version": "2.1.1", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "callr", + "cli", + "clipr", + "fs", + "glue", + "knitr", + "lifecycle", + "rlang", + "rmarkdown", + "rstudioapi", + "utils", + "withr" + ], + "Hash": "97b1d5361a24d9fb588db7afe3e5bcbf" + }, "rlang": { "Package": "rlang", "Version": "1.1.5", @@ -1081,6 +1761,37 @@ ], "Hash": "a9881dfed103e83f9de151dc17002cd1" }, + "rvest": { + "Package": "rvest", + "Version": "1.0.4", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "cli", + "glue", + "httr", + "lifecycle", + "magrittr", + "rlang", + "selectr", + "tibble", + "xml2" + ], + "Hash": "0bcf0c6f274e90ea314b812a6d19a519" + }, + "s2": { + "Package": "s2", + "Version": "1.1.7", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "Rcpp", + "wk" + ], + "Hash": "3c8013cdd7f1d20de5762e3f97e5e274" + }, "sass": { "Package": "sass", "Version": "0.4.9", @@ -1095,6 +1806,39 @@ ], "Hash": "d53dbfddf695303ea4ad66f86e99b95d" }, + "scales": { + "Package": "scales", + "Version": "1.3.0", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "R6", + "RColorBrewer", + "cli", + "farver", + "glue", + "labeling", + "lifecycle", + "munsell", + "rlang", + "viridisLite" + ], + "Hash": "c19df082ba346b0ffa6f833e92de34d1" + }, + "selectr": { + "Package": "selectr", + "Version": "0.4-2", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "R6", + "methods", + "stringr" + ], + "Hash": "3838071b66e0c566d55cc26bd6e27bf4" + }, "sessioninfo": { "Package": "sessioninfo", "Version": "1.2.2", @@ -1108,6 +1852,29 @@ ], "Hash": "3f9796a8d0a0e8c6eb49a4b029359d1f" }, + "sf": { + "Package": "sf", + "Version": "1.0-19", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "DBI", + "R", + "Rcpp", + "classInt", + "grDevices", + "graphics", + "grid", + "magrittr", + "methods", + "s2", + "stats", + "tools", + "units", + "utils" + ], + "Hash": "fe02eec2f6b3ba0e24afe83d5ccfb528" + }, "shiny": { "Package": "shiny", "Version": "1.10.0", @@ -1279,6 +2046,51 @@ ], "Hash": "a84e2cc86d07289b3b6f5069df7a004c" }, + "tidyRSS": { + "Package": "tidyRSS", + "Version": "2.0.7", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "anytime", + "dplyr", + "glue", + "httr", + "jsonlite", + "magrittr", + "purrr", + "rlang", + "tibble", + "tidyselect", + "vctrs", + "xml2" + ], + "Hash": "bfd32a976e5ac80838ece3256cd7f810" + }, + "tidyr": { + "Package": "tidyr", + "Version": "1.3.1", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "cli", + "cpp11", + "dplyr", + "glue", + "lifecycle", + "magrittr", + "purrr", + "rlang", + "stringr", + "tibble", + "tidyselect", + "utils", + "vctrs" + ], + "Hash": "915fb7ce036c22a6a33b5a8adb712eb1" + }, "tidyselect": { "Package": "tidyselect", "Version": "1.2.1", @@ -1318,6 +2130,46 @@ ], "Hash": "612125521ebc22fd028182761211b5d9" }, + "tidyverse": { + "Package": "tidyverse", + "Version": "2.0.0", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "broom", + "cli", + "conflicted", + "dbplyr", + "dplyr", + "dtplyr", + "forcats", + "ggplot2", + "googledrive", + "googlesheets4", + "haven", + "hms", + "httr", + "jsonlite", + "lubridate", + "magrittr", + "modelr", + "pillar", + "purrr", + "ragg", + "readr", + "readxl", + "reprex", + "rlang", + "rstudioapi", + "rvest", + "stringr", + "tibble", + "tidyr", + "xml2" + ], + "Hash": "c328568cd14ea89a83bd4ca7f54ae07e" + }, "timechange": { "Package": "timechange", "Version": "0.3.0", @@ -1352,6 +2204,28 @@ ], "Hash": "76d35ebfaaf291e08c15696c9f2ec96d" }, + "tzdb": { + "Package": "tzdb", + "Version": "0.4.0", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "cpp11" + ], + "Hash": "f561504ec2897f4d46f0c7657e488ae1" + }, + "units": { + "Package": "units", + "Version": "0.8-5", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "Rcpp" + ], + "Hash": "119d19da480e873f72241ff6962ffd83" + }, "urlchecker": { "Package": "urlchecker", "Version": "1.0.1", @@ -1408,6 +2282,16 @@ ], "Hash": "62b65c52671e6665f803ff02954446e9" }, + "uuid": { + "Package": "uuid", + "Version": "1.2-1", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R" + ], + "Hash": "34e965e62a41fcafb1ca60e9b142085b" + }, "vctrs": { "Package": "vctrs", "Version": "0.6.5", @@ -1422,6 +2306,42 @@ ], "Hash": "c03fa420630029418f7e6da3667aac4a" }, + "viridisLite": { + "Package": "viridisLite", + "Version": "0.4.2", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R" + ], + "Hash": "c826c7c4241b6fc89ff55aaea3fa7491" + }, + "vroom": { + "Package": "vroom", + "Version": "1.6.5", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "bit64", + "cli", + "cpp11", + "crayon", + "glue", + "hms", + "lifecycle", + "methods", + "progress", + "rlang", + "stats", + "tibble", + "tidyselect", + "tzdb", + "vctrs", + "withr" + ], + "Hash": "390f9315bc0025be03012054103d227c" + }, "waldo": { "Package": "waldo", "Version": "0.6.1", @@ -1456,6 +2376,16 @@ ], "Hash": "cc2d62c76458d425210d1eb1478b30b4" }, + "wk": { + "Package": "wk", + "Version": "0.9.4", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R" + ], + "Hash": "37be35d733130f1de1ef51672cf7cdc0" + }, "xfun": { "Package": "xfun", "Version": "0.50", diff --git a/tests/testthat/test-s3_constructors.R b/tests/testthat/test-s3_constructors.R new file mode 100644 index 0000000..5e4debf --- /dev/null +++ b/tests/testthat/test-s3_constructors.R @@ -0,0 +1,159 @@ +test_that("new_dkstat_Denmark_municipality_07 assigns the class properly", { + df <- data.frame( + x = 1:999, + y = 999:1 + ) |> + new_dkstat_Denmark_municipality_07() + + expect_s3_class(df, "dkstat_Denmark_municipality_07") +}) + +test_that("new_dkstat_KOMGRP assigns the class properly", { + df <- data.frame( + x = 1:999, + y = 999:1 + ) |> + new_dkstat_KOMGRP() + + expect_s3_class(df, "dkstat_KOMGRP") +}) + +test_that("new_dkstat_kom_omraade assigns the class properly", { + df <- data.frame( + x = 1:999, + y = 999:1 + ) |> + new_dkstat_kom_omraade() + + expect_s3_class(df, "dkstat_kom_omraade") +}) + +test_that("new_dkstat_Verden_dk2 assigns the class properly", { + df <- data.frame( + x = 1:999, + y = 999:1 + ) |> + new_dkstat_Verden_dk2() + + expect_s3_class(df, "dkstat_Verden_dk2") +}) + +test_that("new_dkstat_denmark_cities_19 assigns the class properly", { + df <- data.frame( + x = 1:999, + y = 999:1 + ) |> + new_dkstat_denmark_cities_19() + + expect_s3_class(df, "dkstat_denmark_cities_19") +}) + +test_that("new_dkstat_denmark_parish_23_4c assigns the class properly", { + df <- data.frame( + x = 1:999, + y = 999:1 + ) |> + new_dkstat_denmark_parish_23_4c() + + expect_s3_class(df, "dkstat_denmark_parish_23_4c") +}) + +test_that("new_dkstat_denmark_municipalitygroups_24 assigns the class properly", { + df <- data.frame( + x = 1:999, + y = 999:1 + ) |> + new_dkstat_denmark_municipalitygroups_24() + + expect_s3_class(df, "dkstat_denmark_municipalitygroups_24") +}) + +test_that("new_dkstat_Denmark_region_07 assigns the class properly", { + df <- data.frame( + x = 1:999, + y = 999:1 + ) |> + new_dkstat_Denmark_region_07() + + expect_s3_class(df, "dkstat_Denmark_region_07") +}) + +test_that("new_dkstat_Denmark_rural_07 assigns the class properly", { + df <- data.frame( + x = 1:999, + y = 999:1 + ) |> + new_dkstat_Denmark_rural_07() + + expect_s3_class(df, "dkstat_Denmark_rural_07") +}) + +test_that("new_dkstat_denmark_multimember_constituency_23 assigns the class properly", { + df <- data.frame( + x = 1:999, + y = 999:1 + ) |> + new_dkstat_denmark_multimember_constituency_23() + + expect_s3_class(df, "dkstat_denmark_multimember_constituency_23") +}) + +test_that("new_dkstat_denmark_deanary_23 assigns the class properly", { + df <- data.frame( + x = 1:999, + y = 999:1 + ) |> + new_dkstat_denmark_deanary_23() + + expect_s3_class(df, "dkstat_denmark_deanary_23") +}) + +test_that("new_dkstat_europe_dk assigns the class properly", { + df <- data.frame( + x = 1:999, + y = 999:1 + ) |> + new_dkstat_europe_dk() + + expect_s3_class(df, "dkstat_europe_dk") +}) + +test_that("new_dkstat_Verden_dk assigns the class properly", { + df <- data.frame( + x = 1:999, + y = 999:1 + ) |> + new_dkstat_Verden_dk() + + expect_s3_class(df, "dkstat_Verden_dk") +}) + +test_that("new_dkstat_Europa_DK3 assigns the class properly", { + df <- data.frame( + x = 1:999, + y = 999:1 + ) |> + new_dkstat_Europa_DK3() + + expect_s3_class(df, "dkstat_Europa_DK3") +}) + +test_that("new_dkstat_Denmark_county assigns the class properly", { + df <- data.frame( + x = 1:999, + y = 999:1 + ) |> + new_dkstat_Denmark_county() + + expect_s3_class(df, "dkstat_Denmark_county") +}) + +test_that("new_dkstat_Verden_dk4 assigns the class properly", { + df <- data.frame( + x = 1:999, + y = 999:1 + ) |> + new_dkstat_Verden_dk4() + + expect_s3_class(df, "dkstat_Verden_dk4") +}) diff --git a/vignettes/.gitignore b/vignettes/.gitignore new file mode 100644 index 0000000..097b241 --- /dev/null +++ b/vignettes/.gitignore @@ -0,0 +1,2 @@ +*.html +*.R diff --git a/vignettes/refs.bib b/vignettes/refs.bib new file mode 100644 index 0000000..00e1ba0 --- /dev/null +++ b/vignettes/refs.bib @@ -0,0 +1,11 @@ +@book{adv-r, + title = "Advanced R, second edition", + author = "Wickham, Hadley", + publisher = "CRC Press", + series = "Chapman \& Hall/CRC The R Series", + edition = 2, + month = may, + year = 2019, + address = "Boca Raton, FL", + language = "en" +} diff --git a/vignettes/tech-specs-for-geodk.Rmd b/vignettes/tech-specs-for-geodk.Rmd new file mode 100644 index 0000000..6fa2497 --- /dev/null +++ b/vignettes/tech-specs-for-geodk.Rmd @@ -0,0 +1,152 @@ +--- +title: "Technical specification for intergration with {geodk}" +output: rmarkdown::html_vignette +bibliography: refs.bib +vignette: > + %\VignetteIndexEntry{tech-specs-for-geodk} + %\VignetteEngine{knitr::rmarkdown} + %\VignetteEncoding{UTF-8} +--- + +```{r, include = FALSE} +knitr::opts_chunk$set( + collapse = TRUE, + comment = "#>" +) +``` + +```{r setup, include = FALSE, eval = FALSE} +library(dkstat) +library(geodk) +library(tidyverse) +``` + +# What is this? + +This documents the technical specification for the integration between `{dkstat}` and `{geodk}`. It can be found on this page and in [the `{geodk}` documentation](https://ropengov.github.io/geodk/articles/tech-specs-for-dkstat.html). vignette("tech-specs-for-dkstat", package = "geodk"). + +## Why would you want to read this? + +I honestly don't know. This document is written mostly for me [(Aleksander)](https://aleksanderbl.dk) and contributors to use as a reference when maintaining this integration. If you have any interest in the inner workings of how these two packages interact, then please do read on. + +# Integration usage + +A thorough usage guide can be found in vignette("geodk", package = "dkstat"), but below I will provide a technical walkthrough of the integration. + +## Main goal + +The main goal of the integration between `{dkstat}` and `{geodk}` is to be able to run the following code and have meaningful geographic information added to the statistics. + +```{r main-goal, eval = FALSE} +dkstat::dst_get_all_data("laby04") |> + geodk::geodk_enrich() # This function name is still debatable. +``` + +## Problem description + +When accessing data from a table, e.g. "laby04" there is no obvious way to know what column is geographic. + +```{r} +dkstat::dst_get_all_data("laby01") |> + dplyr::distinct(KOMGRP, .keep_all = TRUE) |> + tail() +``` + +When looking at the above tail, I (and probably you, as well) can recognise that the `OMRÅDE` column is the geographic one. + +### Tables with multiple geographic levels + +Some tables, e.g. "laby04" has multiple geographic levels. This table has a grouping of municipalities and then the individual municipalities. To ensure that the individuals *and* groups are enriched properly, we have to take the different levels into account in the method. + +# S3 methods + +Below you can find the description of each S3-class that is used (/abused) to enrich the statistical data with geographic information. It is sectioned by the geographic grouping of the dataset. Before we dive into the specific classes, I will first outline the general idea. For more information on the specific terminology used, please consult @adv-r. + +## Classes + +Each type of geographic variable has its own S3 class. The class is determined by what observations is included in the variable. The class-assignment is done by a series of custom class-constructors called `new_dkstat_*()`. One example is `new_dkstat_Denmark_municipality_07()` which assigns the S3 class `dkstat_Denmark_municipality_07` to a dataset. The class is assigned "after the fact", as Wickham calls it, ensuring that the usual behaviour of a data.frame is preserved, through inheritance for all the functions that don't know about these special classes (e.g. the `{dplyr}` functions). Thus, the dkstat-classes are subclasses of `data.frame`. The class names are derived from the API and maps 1:1 to the `map` value that is returned for geographic variables. + +## Method dispatch + +The S3 generic can be found in `geodk::geodk_enrich()`. The individual methods also live in `{geodk}`. This is to not take on `{geodk}` as a dependency in `{dkstat}`. The S3 method for the municipality group (Denmark_municipality_07) from above is called `geodk_enrich.dkstat_Denmark_municipality_07()`. Please [open an issue](https://github.com/rOpenGov/geodk/issues) if you would like to help add a method from another data source. + +# Custom classes + +The API provides 14 different map-levels from which I have based the classes. This makes it very easy to add the right one. In `{dkstat}` `data-raw/dst_map.R` you can find a script that checks all tables for *map* variables and adds each new one to a list. This gives the below vector. + +```{r} +#> [1] "Denmark_municipality_07" "Verden_dk2" +#> [3] "denmark_cities_19" "denmark_parish_23_4c" +#> [5] "denmark_municipalitygroups_24" "Denmark_region_07" +#> [7] "Denmark_rural_07" "denmark_multimember_constituency_23" +#> [9] "denmark_deanary_23" "europe_dk" +#> [11] "Verden_dk" "Europa_DK3" +#> [13] "Denmark_county" "Verden_dk4" +``` + +Some of the geographic levels, such as "Verden_dk" includes other countries. This data is not available from `{geodk}` thus leading to a message for the user informing them of this and then asking if it should add geometry for Denmark. + +## Denmark_municipality_07 - Municipalities and groups + +The municipality grouping that are specified by Statistics Denmark are described [on this website](https://www.dst.dk/da/Statistik/dokumentation/nomenklaturer/kommunegrupper). This grouping includes both the individual municipality and five groupings. Take a look at the link if you would like to learn more. In the `{geodk}` backend I have created a list containing all the municipality names with both Statistics Denmark-naming and geodk-naming. In addition to that, the list is ordered by the municipality grouping. + +This grouping is assigned the `dkstat_Denmark_municipality_07` class in addition to the `data.frame` class it already has. + +The method for `dkstat_Denmark_municipality_07` first filters the groupings from the individual municipalities. A list of the individual municipalities and groupings, along with their specific ids is stored in `{geodk}`. It is not exported to the user. + +After filtering, it assigns the individual municipality geometries. The grouping geometries are also assigned as well as a column indicating the geographic nature of the observation - Is it a overall grouping or an individual municipality? + +The municipalities that make up the groupings are split per group and run through `sf::st_union()` to be returned as a `sf` geometry per group. + +## Verden_dk2 + + +## denmark_cities_19 + + +## denmark_parish_23_4c + + +## denmark_municipalitygroups_24 + + +## Denmark_region_07 + + +## Denmark_rural_07 + + +## denmark_multimember_constituency_23 + + +## denmark_deanary_23 + + +## europe_dk + + +## Verden_dk + + +## Europa_DK3 + + +## Denmark_county + + +## Verden_dk4 + +# References + + + + + + + + + + + + +