doc-all: Download data from the PX-Web API of Statistics Finland

doc-allR Documentation

Download data from the PX-Web API of Statistics Finland

Description

px_nav is used to navigate the API: it returns the possible subdirectories as a tibble with dbid corresponding to the suffix in the url that points to the given subdirectory.

Usage

px_nav(path = "", api = "https://statfin.stat.fi/PXWeb/api/v1/fi/")

px_var(path, api = "https://statfin.stat.fi/PXWeb/api/v1/fi/")

px_dl(
  path,
  var = px_var(path, api),
  simplify_colnames = FALSE,
  na_omit = FALSE,
  api = "https://statfin.stat.fi/PXWeb/api/v1/fi/"
)

Arguments

path

suffix to the path after api. For px_download and px_var this must point to an actual dataset (ie. an url ending in .px), whereas for px_nav this should correspond to a partial path to a dataset (ie. an url that points to a directory). Defaults to "".

api

The url to the API. Defaults to "https://statfin.stat.fi/PXWeb/api/v1/fi/", the Finnish PX-Web API of Statistics Finland.

var

The values of the dimensions to be queried as a tibble. Can be obtained by filtering from the result of px_var. If not specified, px_var is called automatically.

simplify_colnames

If TRUE, the colnames are transformed to ascii, lowercase and spaces are replaced with underscores.

na_omit

If TRUE, all missing values are omitted. Defaults to FALSE.

Details

px_var returns the values of the dimensions in the given table and px_dl returns the actual data corresponding to variables specified as the var argument. The format of the var argument is the same as in the tibble returned by px_var, so the values can be selected by filtering that tibble. See the examples for mode information.

Value

px_dl and px_var always return a tibble. px_nav returns a tibble when request is sent to a non-table URL (ie. an url corresponds to a directory rather than a particular data set).

Examples

# Navigate through the API
# px_nav()
# check what data is available under StatFin
# px_nav("StatFin/")
# navigate through the directories,
# check what variables are available for population statistics
# var <- px_var("StatFin/vrm/synt/statfin_synt_pxt_12dj.px",
#               "https://statfin.stat.fi/PXWeb/api/v1/en/")
# select years after 1900
# var_1900 <- dplyr::filter(var, Year >= 1900)
# Download the data, starting from year 1900,
# omitting the var-argument would download the data for all the years.
# data <- px_dl("StatFin/vrm/synt/statfin_synt_pxt_12dj.px",
#               var = var_1900, simplify_colnames = TRUE,
#               api = "https://statfin.stat.fi/PXWeb/api/v1/en/")


paasim/simplepx documentation built on Oct. 20, 2022, 7:58 a.m.