Download a dataset from the PXWeb API of the BFS with its BFS number.
Find the BFS number with bfs_get_catalog_data() or on the BFS website.
Usage
bfs_get_data(
number_bfs,
language = "de",
query = NULL,
column_name_type = "text",
variable_value_type = "text",
clean_names = FALSE,
delay = NULL
)Arguments
- number_bfs
The BFS number of a dataset, e.g.
"px-x-1502040100_131".- language
Language of the dataset:
"de"(default),"fr","it"or"en".- query
Optional selection of the data: a named list with the variable codes as names and the value codes as values (columns
codeandvaluesofbfs_get_metadata()), e.g.list(Jahr = c("40", "41"), Geschlecht = "*")."*"selects all values. A variable not inqueryis left out of the result (totals over it), if the dataset allows it. IfNULL(default), the whole dataset is downloaded.- column_name_type
Column names as
"text"(label, default) or"code".- variable_value_type
Values as
"text"(label, default) or"code".- clean_names
If
TRUE, clean the column names withjanitor::clean_names().- delay
Optional number of seconds to wait before downloading the data, to avoid "Too Many Requests" errors when calling the API in a loop.
Details
Large datasets can exceed the limits of the API: select only the data you
need with query, or download the whole file with bfs_download_asset().
The PXWeb API is the API of STAT-TAB, which the BFS is replacing with the
Swiss Stats Explorer: check first if the statistic is on
https://stats.swiss/ and use bfs_sse_data().
