MyNixOS website logo
Description

R Client for the Statistics Denmark Databank API.

The purpose of the package is to enable an R function interface into the Statistics Denmark Databank API mainly for research purposes. The Statistics Denmark Databank API has four endpoints, see here for more information and testing the API in their console: <https://www.dst.dk/en/Statistik/brug-statistikken/muligheder-i-statistikbanken/api>. This package mimics the structure of the API and provides four main functions to match the functionality of the API endpoints.

Travis buildstatus CRANstatus Since when

Installation

From CRAN:

install.packages("danstat")

From Github:

# install.packages("devtools")
devtools::install_github("ValeriVoev/danstat")

Overview

The danstat package provides an R interface to Danmarks Statistik Statistikbank API to enable an easier access to the wealth of data in the data bank for research and the general community. The documentation of the API can be found here: Databank API.

Usage

The API has 4 endpoints which are mimicked by four main functions of the package:

  1. get_subjects() (SUBJECTS endpoint) retrieves information about subjects around which the data tables in the data bank are organized. The subjects are arranged hierarchically highest level like “Labour and income”, “Transport”, etc. get_subjects() retrieves the highest level of the hierarchy. See the function documentation for more details.
  2. get_tables() (TABLES endpoint) retrieves a list of tables associated with a given subject code. For example get_tables(subjects = "2") retrieves all tables related to the subject “Labour and income” with table id, description, variables in the table, etc.
  3. get_table_metadata() (TABLEINFO endpoint) returns information about a particular table - description, time of last update, whether or not it is actively updated, and most importantly (for practical purposes) the variable names and id’s which are needed whenever you request actual data from the table. Set variables_only = TRUE if you only want to get information on the table variables.
  4. get_data() (DATA endpoint) - returns data from a selected table. It is required to include a variables argument as a list. Each element of the list should itself be a named list (with elements code and values) where code is the variable id for which data is requested, and values is a vector of values for this variable. If all values are requested, specify values = NA. For example:
library(danstat)
user_input = list(list(code = "ieland", values = c(5100, 5128)),
                  list(code = "køn", values = c(1,2)),
                  list(code = "tid", values = NA))

get_data(table_id = "folk1c", variables = user_input)
#> # A tibble: 192 x 4
#>   IELAND  KØN   TID    INDHOLD
#>   <chr>   <chr> <chr>    <dbl>
#> 1 Denmark Men   2008Q1 2465810
#> 2 Denmark Men   2008Q2 2466036
#> 3 Denmark Men   2008Q3 2467712
#> 4 Denmark Men   2008Q4 2469977
#> 5 Denmark Men   2009Q1 2470457
#> # … with 187 more rows

Note that while default language is set to English and variable values are indeed returned in English, e.g. “Men”, column names are returned in Danish, e.g. “KØN”, “INDHOLD”, etc. Unfortunately, the API doesn’t currently provide an option to return column names (variable names) in English. However, you can get the English translation using get_table_metadata. For example, for the above table

library(dplyr)
get_table_metadata(table_id = "folk1c", variables_only = TRUE) %>% 
    select(id, text)
#>         id              text
#> 1   OMRÅDE            region
#> 2      KØN               sex
#> 3    ALDER               age
#> 4 HERKOMST          ancestry
#> 5   IELAND country of origin
#> 6      Tid              time

we can see that “Område” translates to “region”, “Køn” to “sex”, “Alder” to “age”, etc. “Indhold” is always the “value” column whenever data is returned with the get_data function.

See also

There are (as far as I know) two other packages with similar functionality:

In the packages above, the API is called with a GET request, while POST is the prefrerred option of the API developers and is also what is used in this package. Also, I think that using POST requests makes the package code more readable compared to the long url-encoded queries needed for GET requests. Also, as of this moment, the rOpenGov package seems to not have been maintained for the past 3 years. In any case, users can consider the above 2 packages as alternatives to this one.

Metadata

Version

0.2.0

License

Unknown

Platforms (77)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-freebsd
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64-windows
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows