From e1c0f4954dfa23cf8fc59358a4872fb57c529a55 Mon Sep 17 00:00:00 2001 From: aleksanderbl29 <73799306+aleksanderbl29@users.noreply.github.com> Date: Fri, 15 Nov 2024 18:07:27 +0100 Subject: [PATCH 1/7] Add function to retrieve all data from a provided table --- NAMESPACE | 1 + R/dst_get_all_data.R | 47 +++++++++++++++++++++++++++++++++++++++++ man/dst_get_all_data.Rd | 17 +++++++++++++++ 3 files changed, 65 insertions(+) create mode 100644 R/dst_get_all_data.R create mode 100644 man/dst_get_all_data.Rd diff --git a/NAMESPACE b/NAMESPACE index bd5368c..3ee0768 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,4 +1,5 @@ export(dst_get_data) +export(dst_get_all_data) export(dst_meta) export(dst_search) export(dst_get_tables) diff --git a/R/dst_get_all_data.R b/R/dst_get_all_data.R new file mode 100644 index 0000000..327cfa4 --- /dev/null +++ b/R/dst_get_all_data.R @@ -0,0 +1,47 @@ +#' This function returns the entire table requested data from the StatBank. +#' (http://www.statistikbanken.dk/statbank5a/ or http://www.dst.dk) +#' +#' Get all data from a table in the StatBank. +#' +#' @export +#' @inheritParams dst_get_data +dst_get_all_data <- function(table, lang = "da") { + + # Get metadata for table + metadata <- dst_meta(table) + + # Extract variable names from metadata + variable_names <- get_vars(metadata) + + # Get all options for each variable as a query-list + query <- get_var_options(metadata, variable_names) + + # Request table with query params + data <- dst_get_data( + table = table, + query = query + ) + + return(data) +} + +#' This function extracts the variables from metadata +#' @noRd +get_vars <- function(metadata) { + vars <- metadata$variables[["id"]] + return(vars) +} + +#' This function gets all the options for a provided list of variable names +#' given some metadata +#' @noRd +get_var_options <- function(metadata, variable_names) { + query <- list() + + for (var in variable_names) { + query[var] <- var + + query[var][var] <- metadata$values[[var]]["text"] + } + return(query) +} \ No newline at end of file diff --git a/man/dst_get_all_data.Rd b/man/dst_get_all_data.Rd new file mode 100644 index 0000000..e0a5d68 --- /dev/null +++ b/man/dst_get_all_data.Rd @@ -0,0 +1,17 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/dst_get_all_data.R +\name{dst_get_all_data} +\alias{dst_get_all_data} +\title{This function returns the entire table requested data from the StatBank. +(http://www.statistikbanken.dk/statbank5a/ or http://www.dst.dk)} +\usage{ +dst_get_all_data(table, lang = "da") +} +\arguments{ +\item{table}{Table from StatBank.} + +\item{lang}{language. "en" for english or "da" for danish.} +} +\description{ +Get all data from a table in the StatBank. +} From 4f5c44156a267614845b73f5d1f6386360956e60 Mon Sep 17 00:00:00 2001 From: aleksanderbl29 <73799306+aleksanderbl29@users.noreply.github.com> Date: Fri, 15 Nov 2024 18:08:05 +0100 Subject: [PATCH 2/7] Add my info to description and update version and date --- DESCRIPTION | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 6d9b4bb..5ad5f7f 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,11 +1,12 @@ Type: Package Package: dkstat Title: API connection to the StatBank from Statistics Denmark. -Version: 0.08 -Date: 2015-09-20 +Version: 0.09 +Date: 2024-11-15 Authors@R: c( person("Kenneth", "Rose", , "kennethrose82@gmail.com", role = c("aut", "cre")), - person("Thomas J.", "leeper", role = "ctb") + person("Thomas J.", "leeper", role = "ctb"), + person("Aleksander", "Bang-Larsen", "contact@aleksanderbl.dk", role = "ctb") ) Maintainer: Kenneth Rose Description: This package provides a few simple functions that can be used From 71de2347e93737158915b9bf251767c353f391b7 Mon Sep 17 00:00:00 2001 From: aleksanderbl29 <73799306+aleksanderbl29@users.noreply.github.com> Date: Fri, 15 Nov 2024 18:15:26 +0100 Subject: [PATCH 3/7] Add function family and author information --- R/dst_get_all_data.R | 2 ++ R/dst_get_data.R | 1 + 2 files changed, 3 insertions(+) diff --git a/R/dst_get_all_data.R b/R/dst_get_all_data.R index 327cfa4..682e68d 100644 --- a/R/dst_get_all_data.R +++ b/R/dst_get_all_data.R @@ -5,6 +5,8 @@ #' #' @export #' @inheritParams dst_get_data +#' @family Data retrival functions +#' @author Aleksander Bang-Larsen dst_get_all_data <- function(table, lang = "da") { # Get metadata for table diff --git a/R/dst_get_data.R b/R/dst_get_data.R index 043b495..dd581f5 100644 --- a/R/dst_get_data.R +++ b/R/dst_get_data.R @@ -14,6 +14,7 @@ #' need to select a value for each of the parameters. #' @param value_presentation For now, "value" or "default" #' @export +#' @family Data retrival functions dst_get_data <- function(table, ..., query = NULL, parse_dst_tid = TRUE, lang = "da", meta_data = NULL, format = "CSV", value_presentation = "Value"){ From 18bdecfedeb0df0bf4cd19ecdb13f69e70134dcb Mon Sep 17 00:00:00 2001 From: aleksanderbl29 <73799306+aleksanderbl29@users.noreply.github.com> Date: Fri, 15 Nov 2024 18:15:47 +0100 Subject: [PATCH 4/7] Update roxygen and re-render documentation --- DESCRIPTION | 2 +- man/dst_correct_url.Rd | 1 - man/dst_date_parse.Rd | 1 - man/dst_find_val_id.Rd | 1 - man/dst_get_all_data.Rd | 8 ++++++++ man/dst_get_data.Rd | 18 +++++++++++++++--- man/dst_get_tables.Rd | 1 - man/dst_meta.Rd | 1 - man/dst_meta_parse.Rd | 1 - man/dst_query_match.Rd | 1 - man/dst_search.Rd | 4 +--- man/dst_value_limit.Rd | 1 - 12 files changed, 25 insertions(+), 15 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 5ad5f7f..9f0b493 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -27,6 +27,6 @@ Remotes: sebastianbarfort/mapDK Encoding: UTF-8 Roxygen: list(wrap = FALSE) -RoxygenNote: 5.0.1 +RoxygenNote: 7.3.2 X-schema.org-isPartOf: http://ropengov.org/ X-schema.org-keywords: ropengov diff --git a/man/dst_correct_url.Rd b/man/dst_correct_url.Rd index d6339ed..560af32 100644 --- a/man/dst_correct_url.Rd +++ b/man/dst_correct_url.Rd @@ -12,4 +12,3 @@ dst_correct_url(url) \description{ Corrects url encoding for Danish letters. } - diff --git a/man/dst_date_parse.Rd b/man/dst_date_parse.Rd index dd05b1c..fd70ff2 100644 --- a/man/dst_date_parse.Rd +++ b/man/dst_date_parse.Rd @@ -13,4 +13,3 @@ dst_date_parse(dst_date) \description{ Helper function to parse the dates from the statbank. } - diff --git a/man/dst_find_val_id.Rd b/man/dst_find_val_id.Rd index 7f77902..b23f5b2 100644 --- a/man/dst_find_val_id.Rd +++ b/man/dst_find_val_id.Rd @@ -18,4 +18,3 @@ dst_find_val_id(meta_data, variable, values_text = NULL) This is a helper function to extract the ID's in the values list that the dst_meta function returns. } - diff --git a/man/dst_get_all_data.Rd b/man/dst_get_all_data.Rd index e0a5d68..e6211e7 100644 --- a/man/dst_get_all_data.Rd +++ b/man/dst_get_all_data.Rd @@ -15,3 +15,11 @@ dst_get_all_data(table, lang = "da") \description{ Get all data from a table in the StatBank. } +\seealso{ +Other Data retrival functions: +\code{\link{dst_get_data}()} +} +\author{ +Aleksander Bang-Larsen +} +\concept{Data retrival functions} diff --git a/man/dst_get_data.Rd b/man/dst_get_data.Rd index b83442e..20ea2c0 100644 --- a/man/dst_get_data.Rd +++ b/man/dst_get_data.Rd @@ -5,8 +5,16 @@ \title{This function returns the requested data from the StatBank table. (http://www.statistikbanken.dk/statbank5a/ or http://www.dst.dk)} \usage{ -dst_get_data(table, ..., query = NULL, parse_dst_tid = TRUE, lang = "da", - meta_data = NULL, format = "CSV", value_presentation = "Value") +dst_get_data( + table, + ..., + query = NULL, + parse_dst_tid = TRUE, + lang = "da", + meta_data = NULL, + format = "CSV", + value_presentation = "Value" +) } \arguments{ \item{table}{Table from StatBank.} @@ -30,4 +38,8 @@ need to select a value for each of the parameters.} \description{ Get data from a table in the StatBank. } - +\seealso{ +Other Data retrival functions: +\code{\link{dst_get_all_data}()} +} +\concept{Data retrival functions} diff --git a/man/dst_get_tables.Rd b/man/dst_get_tables.Rd index 28c9607..bb436f5 100644 --- a/man/dst_get_tables.Rd +++ b/man/dst_get_tables.Rd @@ -12,4 +12,3 @@ dst_get_tables(lang = "da") \description{ This functions downloads all the available tables. } - diff --git a/man/dst_meta.Rd b/man/dst_meta.Rd index 7ca9452..653414b 100644 --- a/man/dst_meta.Rd +++ b/man/dst_meta.Rd @@ -18,4 +18,3 @@ dst_meta(table, ..., lang = "da") This function POSTs a request for meta data on a table from Statistics Denmark and returns a JSON object with the information. } - diff --git a/man/dst_meta_parse.Rd b/man/dst_meta_parse.Rd index 3af92e6..2367cca 100644 --- a/man/dst_meta_parse.Rd +++ b/man/dst_meta_parse.Rd @@ -18,4 +18,3 @@ Some tables are VERY large, so the basic request is rather simple. The function returns a list with basic data, info on available variables and a list with a basic request. } - diff --git a/man/dst_query_match.Rd b/man/dst_query_match.Rd index 46c377d..029cc1d 100644 --- a/man/dst_query_match.Rd +++ b/man/dst_query_match.Rd @@ -14,4 +14,3 @@ dst_query_match(table, lang, meta_data, query, format) \description{ This is a helper function to return the ids based on the text values. } - diff --git a/man/dst_search.Rd b/man/dst_search.Rd index 8dc015c..292cfc1 100644 --- a/man/dst_search.Rd +++ b/man/dst_search.Rd @@ -5,8 +5,7 @@ \title{This function provides a search function for the description field of available data series} \usage{ -dst_search(string = "gpd", field = "text", lang = "da", - use_cache = NULL) +dst_search(string = "gpd", field = "text", lang = "da", use_cache = NULL) } \arguments{ \item{string}{Character string. Speficies the search term.} @@ -21,4 +20,3 @@ dst_search(string = "gpd", field = "text", lang = "da", This function provides a search function for the description field of available data series } - diff --git a/man/dst_value_limit.Rd b/man/dst_value_limit.Rd index 38aafd6..157a55f 100644 --- a/man/dst_value_limit.Rd +++ b/man/dst_value_limit.Rd @@ -13,4 +13,3 @@ This is a helper function that returns the number of values the call will return. The API has a limit of 100.000 values. } - From ae643627c773c7ea9e8cc6e2314405ebf85ce1ba Mon Sep 17 00:00:00 2001 From: aleksanderbl29 <73799306+aleksanderbl29@users.noreply.github.com> Date: Fri, 15 Nov 2024 18:18:32 +0100 Subject: [PATCH 5/7] Add ORCID and email --- DESCRIPTION | 3 ++- R/dst_get_all_data.R | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 9f0b493..f699970 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -6,7 +6,8 @@ Date: 2024-11-15 Authors@R: c( person("Kenneth", "Rose", , "kennethrose82@gmail.com", role = c("aut", "cre")), person("Thomas J.", "leeper", role = "ctb"), - person("Aleksander", "Bang-Larsen", "contact@aleksanderbl.dk", role = "ctb") + person("Aleksander", "Bang-Larsen", "contact@aleksanderbl.dk", role = "ctb", + comment = c(ORCID = "0009-0007-7984-4650")) ) Maintainer: Kenneth Rose Description: This package provides a few simple functions that can be used diff --git a/R/dst_get_all_data.R b/R/dst_get_all_data.R index 682e68d..e9f04da 100644 --- a/R/dst_get_all_data.R +++ b/R/dst_get_all_data.R @@ -6,7 +6,7 @@ #' @export #' @inheritParams dst_get_data #' @family Data retrival functions -#' @author Aleksander Bang-Larsen +#' @author Aleksander Bang-Larsen dst_get_all_data <- function(table, lang = "da") { # Get metadata for table From 24eab1349589140723b4cb6b81c8ce3db4192274 Mon Sep 17 00:00:00 2001 From: aleksanderbl29 <73799306+aleksanderbl29@users.noreply.github.com> Date: Fri, 15 Nov 2024 19:03:57 +0100 Subject: [PATCH 6/7] Actually implement language parameter --- R/dst_get_all_data.R | 3 ++- man/dst_get_all_data.Rd | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/R/dst_get_all_data.R b/R/dst_get_all_data.R index e9f04da..9139dc8 100644 --- a/R/dst_get_all_data.R +++ b/R/dst_get_all_data.R @@ -21,7 +21,8 @@ dst_get_all_data <- function(table, lang = "da") { # Request table with query params data <- dst_get_data( table = table, - query = query + query = query, + lang = lang ) return(data) diff --git a/man/dst_get_all_data.Rd b/man/dst_get_all_data.Rd index e6211e7..68f2ea5 100644 --- a/man/dst_get_all_data.Rd +++ b/man/dst_get_all_data.Rd @@ -20,6 +20,6 @@ Other Data retrival functions: \code{\link{dst_get_data}()} } \author{ -Aleksander Bang-Larsen +Aleksander Bang-Larsen } \concept{Data retrival functions} From e916a36571641b2af24f62540a89331a79dfeb89 Mon Sep 17 00:00:00 2001 From: aleksanderbl29 <73799306+aleksanderbl29@users.noreply.github.com> Date: Sun, 17 Nov 2024 16:13:23 +0100 Subject: [PATCH 7/7] Add usecase, statement of need and longer description --- R/dst_get_all_data.R | 7 ++++++- man/dst_get_all_data.Rd | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/R/dst_get_all_data.R b/R/dst_get_all_data.R index 9139dc8..78e6faf 100644 --- a/R/dst_get_all_data.R +++ b/R/dst_get_all_data.R @@ -1,7 +1,12 @@ #' This function returns the entire table requested data from the StatBank. #' (http://www.statistikbanken.dk/statbank5a/ or http://www.dst.dk) #' -#' Get all data from a table in the StatBank. +#' @description Get all data from a table in the StatBank. This function +#' 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. `{dplyr}` functions or +#' save the entire table for archival. #' #' @export #' @inheritParams dst_get_data diff --git a/man/dst_get_all_data.Rd b/man/dst_get_all_data.Rd index 68f2ea5..ee273ac 100644 --- a/man/dst_get_all_data.Rd +++ b/man/dst_get_all_data.Rd @@ -13,7 +13,12 @@ dst_get_all_data(table, lang = "da") \item{lang}{language. "en" for english or "da" for danish.} } \description{ -Get all data from a table in the StatBank. +Get all data from a table in the StatBank. This function + 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. `{dplyr}` functions or + save the entire table for archival. } \seealso{ Other Data retrival functions: