-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
Add function to return all data from a table
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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", , "[email protected]", role = c("aut", "cre")), | ||
person("Thomas J.", "leeper", role = "ctb") | ||
person("Thomas J.", "leeper", role = "ctb"), | ||
person("Aleksander", "Bang-Larsen", "[email protected]", role = "ctb", | ||
comment = c(ORCID = "0009-0007-7984-4650")) | ||
) | ||
Maintainer: Kenneth Rose <[email protected]> | ||
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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export(dst_get_data) | ||
export(dst_get_all_data) | ||
export(dst_meta) | ||
export(dst_search) | ||
export(dst_get_tables) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <contact@@aleksanderbl.dk> | ||
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) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.