diff --git a/DESCRIPTION b/DESCRIPTION index 6d9b4bb..f699970 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,11 +1,13 @@ 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", + comment = c(ORCID = "0009-0007-7984-4650")) ) Maintainer: Kenneth Rose Description: This package provides a few simple functions that can be used @@ -26,6 +28,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/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..78e6faf --- /dev/null +++ b/R/dst_get_all_data.R @@ -0,0 +1,55 @@ +#' This function returns the entire table requested data from the StatBank. +#' (http://www.statistikbanken.dk/statbank5a/ or http://www.dst.dk) +#' +#' @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 +#' @family Data retrival functions +#' @author Aleksander Bang-Larsen +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, + lang = lang + ) + + 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/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"){ 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 new file mode 100644 index 0000000..ee273ac --- /dev/null +++ b/man/dst_get_all_data.Rd @@ -0,0 +1,30 @@ +% 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. 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: +\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. } -