| bfs_sse_data | R Documentation |
Download the data of a dataset of the Swiss Stats Explorer (SSE) API
(https://stats.swiss/). Select the data you need with filters, built
from bfs_sse_dimensions().
bfs_sse_data(
dataset,
...,
filters = NULL,
start_period = NULL,
end_period = NULL,
first_n = NULL,
last_n = NULL,
language = "de",
labels = c("both", "code", "label"),
attributes = FALSE,
version = NULL
)
dataset |
The id of a dataset, e.g. |
... |
These dots are for future extensions and must be empty: the
arguments after |
filters |
A named list: the names are dimensions (column |
start_period, end_period |
Optional first and last period of the data,
e.g. |
first_n, last_n |
Optional number of first or last periods of each
series (each combination of the dimensions), e.g. |
language |
Language of the labels: |
labels |
The values of the dimensions and attributes: |
attributes |
If |
version |
Version of the dataset, e.g. |
The data is downloaded in the SDMX-CSV format, with the labels in
language given by the API. It is smaller and faster to read than the
SDMX-ML format used by bfs_get_sse_data().
The function sends two requests: one for the dimensions of the dataset, to
build the query from filters, and one for the data. The values in
filters are checked by the API: a value not in the dataset gives no
data.
A tibble with one column per dimension, named with the dimension
id whatever the language, then TIME_PERIOD as text (e.g. "2024",
"2024-Q1", "2024-01"), as given by the API, and the observations in
the numeric value column. Returns NULL if there is no internet
connection. The errors have a class, to handle them with
tryCatch():
bfs_no_recordsNo data matches the query.
bfs_sse_filter_errorfilters wouldn't filter the data, e.g.
an unknown dimension.
bfs_sse_argument_errorAnother argument is not valid.
bfs_sse_dataset_errorThe dataset or the version doesn't exist.
bfs_sse_query_errorThe API rejects the query, e.g. a period in a wrong format or a URL too long. The error gives the message of the API.
bfs_http_errorThe API is not available.
Felix Luginbuhl
bfs_sse_datasets(), bfs_sse_dimensions()
bfs_sse_data(
"DF_PASTA_552_MONTHLY",
filters = list(
FREQ = "M",
ACCOMMODATION_TYPE = "552001",
COUNTRY_ORIGIN = c("CH", "AUSL")
),
start_period = "2020",
end_period = "2023",
language = "en"
)
# the latest vacancy rate of each canton
bfs_sse_data(
"DF_LWZ_1",
filters = list(
GR_KT_GDE = c("GE", "ZH", "BE"),
WOHN_ANZAHL = "_T",
LEERWOHN_TYP = "_T",
MEASURE_DIMENSION = "RATE"
),
last_n = 1,
language = "en"
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.